Qucs-GUI
0.0.19
|
00001 /*************************************************************************** 00002 componentdialog.cpp 00003 ------------------- 00004 begin : Tue Sep 9 2003 00005 copyright : (C) 2003, 2004 by Michael Margraf 00006 email : michael.margraf@alumni.tu-berlin.de 00007 ***************************************************************************/ 00008 00009 /*************************************************************************** 00010 * * 00011 * This program is free software; you can redistribute it and/or modify * 00012 * it under the terms of the GNU General Public License as published by * 00013 * the Free Software Foundation; either version 2 of the License, or * 00014 * (at your option) any later version. * 00015 * * 00016 ***************************************************************************/ 00017 00018 #include "componentdialog.h" 00019 #include "main.h" 00020 #include "qucs.h" 00021 #include "schematic.h" 00022 #include "misc.h" 00023 00024 #include <cmath> 00025 00026 #include <QLabel> 00027 #include <QLayout> 00028 #include <QValidator> 00029 #include <QTableWidget> 00030 #include <QHeaderView> 00031 #include <QFileDialog> 00032 #include <QLineEdit> 00033 #include <QCheckBox> 00034 #include <QComboBox> 00035 #include <QGroupBox> 00036 #include <QPushButton> 00037 #include <QDebug> 00038 00039 ComponentDialog::ComponentDialog(Component *c, Schematic *d) 00040 : QDialog(d) 00041 { 00042 resize(450, 250); 00043 setWindowTitle(tr("Edit Component Properties")); 00044 Comp = c; 00045 Doc = d; 00046 QString s; 00047 setAllVisible = true; // state when toggling properties visibility 00048 00049 all = new QVBoxLayout; // to provide neccessary size 00050 this->setLayout(all); 00051 all->setContentsMargins(1,1,1,1); 00052 QGridLayout *gp1; 00053 00054 ValInteger = new QIntValidator(1, 1000000, this); 00055 00056 Expr.setPattern("[^\"=]*"); // valid expression for property 'edit' 00057 Validator = new QRegExpValidator(Expr, this); 00058 Expr.setPattern("[^\"]*"); // valid expression for property 'edit' 00059 Validator2 = new QRegExpValidator(Expr, this); 00060 Expr.setPattern("[\\w_]+"); // valid expression for property 'NameEdit' 00061 ValRestrict = new QRegExpValidator(Expr, this); 00062 00063 checkSim = 0; comboSim = 0; comboType = 0; checkParam = 0; 00064 editStart = 0; editStop = 0; editNumber = 0; 00065 00066 Property *pp = 0; // last property shown elsewhere outside the properties table, not to put in TableView 00067 // ........................................................... 00068 // if simulation component: .TR, .AC, .SW, (.SP ?) 00069 if((Comp->Model[0] == '.') && 00070 (Comp->Model != ".DC") && (Comp->Model != ".HB") && 00071 (Comp->Model != ".Digi") && (Comp->Model != ".ETR")) { 00072 QTabWidget *t = new QTabWidget(this); 00073 all->addWidget(t); 00074 00075 QWidget *Tab1 = new QWidget(t); 00076 t->addTab(Tab1, tr("Sweep")); 00077 QGridLayout *gp = new QGridLayout; 00078 Tab1->setLayout(gp); 00079 00080 gp->addWidget(new QLabel(Comp->Description, Tab1), 0,0,1,2); 00081 00082 int row=1; 00083 editParam = new QLineEdit(Tab1); 00084 editParam->setValidator(ValRestrict); 00085 connect(editParam, SIGNAL(returnPressed()), SLOT(slotParamEntered())); 00086 checkParam = new QCheckBox(tr("display in schematic"), Tab1); 00087 00088 if(Comp->Model == ".SW") { // parameter sweep 00089 textSim = new QLabel(tr("Simulation:"), Tab1); 00090 gp->addWidget(textSim, row,0); 00091 comboSim = new QComboBox(Tab1); 00092 comboSim->setEditable(true); 00093 connect(comboSim, SIGNAL(activated(int)), SLOT(slotSimEntered(int))); 00094 gp->addWidget(comboSim, row,1); 00095 checkSim = new QCheckBox(tr("display in schematic"), Tab1); 00096 gp->addWidget(checkSim, row++,2); 00097 } 00098 else { 00099 editParam->setReadOnly(true); 00100 checkParam->setDisabled(true); 00101 00102 if(Comp->Model == ".TR") // transient simulation ? 00103 editParam->setText("time"); 00104 else { 00105 if(Comp->Model == ".AC") // AC simulation ? 00106 editParam->setText("acfrequency"); 00107 else 00108 editParam->setText("frequency"); 00109 } 00110 } 00111 00112 gp->addWidget(new QLabel(tr("Sweep Parameter:"), Tab1), row,0); 00113 gp->addWidget(editParam, row,1); 00114 gp->addWidget(checkParam, row++,2); 00115 00116 textType = new QLabel(tr("Type:"), Tab1); 00117 gp->addWidget(textType, row,0); 00118 comboType = new QComboBox(Tab1); 00119 00120 QStringList sweeptypes; 00121 sweeptypes << tr("linear") 00122 << tr("logarithmic") 00123 << tr("list") 00124 << tr("constant"); 00125 comboType->insertItems(0, sweeptypes); 00126 00127 gp->addWidget(comboType, row,1); 00128 connect(comboType, SIGNAL(activated(int)), SLOT(slotSimTypeChange(int))); 00129 checkType = new QCheckBox(tr("display in schematic"), Tab1); 00130 gp->addWidget(checkType, row++,2); 00131 00132 textValues = new QLabel(tr("Values:"), Tab1); 00133 gp->addWidget(textValues, row,0); 00134 editValues = new QLineEdit(Tab1); 00135 editValues->setValidator(Validator); 00136 connect(editValues, SIGNAL(returnPressed()), SLOT(slotValuesEntered())); 00137 gp->addWidget(editValues, row,1); 00138 checkValues = new QCheckBox(tr("display in schematic"), Tab1); 00139 gp->addWidget(checkValues, row++,2); 00140 00141 textStart = new QLabel(tr("Start:"), Tab1); 00142 gp->addWidget(textStart, row,0); 00143 editStart = new QLineEdit(Tab1); 00144 editStart->setValidator(Validator); 00145 connect(editStart, SIGNAL(returnPressed()), SLOT(slotStartEntered())); 00146 gp->addWidget(editStart, row,1); 00147 checkStart = new QCheckBox(tr("display in schematic"), Tab1); 00148 gp->addWidget(checkStart, row++,2); 00149 00150 textStop = new QLabel(tr("Stop:"), Tab1); 00151 gp->addWidget(textStop, row,0); 00152 editStop = new QLineEdit(Tab1); 00153 editStop->setValidator(Validator); 00154 connect(editStop, SIGNAL(returnPressed()), SLOT(slotStopEntered())); 00155 gp->addWidget(editStop, row,1); 00156 checkStop = new QCheckBox(tr("display in schematic"), Tab1); 00157 gp->addWidget(checkStop, row++,2); 00158 00159 textStep = new QLabel(tr("Step:"), Tab1); 00160 gp->addWidget(textStep, row,0); 00161 editStep = new QLineEdit(Tab1); 00162 editStep->setValidator(Validator); 00163 connect(editStep, SIGNAL(returnPressed()), SLOT(slotStepEntered())); 00164 gp->addWidget(editStep, row++,1); 00165 00166 textNumber = new QLabel(tr("Number:"), Tab1); 00167 gp->addWidget(textNumber, row,0); 00168 editNumber = new QLineEdit(Tab1); 00169 editNumber->setValidator(ValInteger); 00170 connect(editNumber, SIGNAL(returnPressed()), SLOT(slotNumberEntered())); 00171 gp->addWidget(editNumber, row,1); 00172 checkNumber = new QCheckBox(tr("display in schematic"), Tab1); 00173 gp->addWidget(checkNumber, row++,2); 00174 00175 00176 if(Comp->Model == ".SW") { // parameter sweep 00177 Component *pc; 00178 for(pc=Doc->Components->first(); pc!=0; pc=Doc->Components->next()) { 00179 // insert all schematic available simulations in the Simulation combo box 00180 if(pc != Comp) 00181 if(pc->Model[0] == '.') 00182 comboSim->insertItem(comboSim->count(), pc->Name); 00183 } 00184 qDebug() << "[]" << Comp->Props.first()->Value; 00185 // set selected simulations in combo box to the currently used one 00186 int i = comboSim->findText(Comp->Props.first()->Value); 00187 if (i != -1) // current simulation is in the available simulations list (normal case) 00188 comboSim->setCurrentIndex(i); 00189 else // current simulation not in the available simulations list 00190 comboSim->setEditText(Comp->Props.first()->Value); 00191 00192 checkSim->setChecked(Comp->Props.current()->display); 00193 s = Comp->Props.next()->Value; 00194 checkType->setChecked(Comp->Props.current()->display); 00195 editParam->setText(Comp->Props.next()->Value); 00196 checkParam->setChecked(Comp->Props.current()->display); 00197 } 00198 else { 00199 s = Comp->Props.first()->Value; 00200 checkType->setChecked(Comp->Props.current()->display); 00201 } 00202 pp = Comp->Props.next(); 00203 editStart->setText(pp->Value); 00204 checkStart->setChecked(pp->display); 00205 pp = Comp->Props.next(); 00206 editStop->setText(pp->Value); 00207 checkStop->setChecked(pp->display); 00208 pp = Comp->Props.next(); // remember last property for ListView 00209 editNumber->setText(pp->Value); 00210 checkNumber->setChecked(pp->display); 00211 00212 int tNum = 0; 00213 if(s[0] == 'l') { 00214 if(s[1] == 'i') { 00215 if(s[2] != 'n') 00216 tNum = 2; 00217 } 00218 else tNum = 1; 00219 } 00220 else tNum = 3; 00221 comboType->setCurrentIndex(tNum); 00222 00223 slotSimTypeChange(tNum); // not automatically ?!? 00224 if(tNum > 1) { 00225 editValues->setText( 00226 editNumber->text().mid(1, editNumber->text().length()-2)); 00227 checkValues->setChecked(Comp->Props.current()->display); 00228 editNumber->setText("2"); 00229 } 00230 slotNumberChanged(0); 00231 00232 /* connect(editValues, SIGNAL(textChanged(const QString&)), 00233 SLOT(slotTextChanged(const QString&)));*/ 00234 connect(editStart, SIGNAL(textChanged(const QString&)), 00235 SLOT(slotNumberChanged(const QString&))); 00236 connect(editStop, SIGNAL(textChanged(const QString&)), 00237 SLOT(slotNumberChanged(const QString&))); 00238 connect(editStep, SIGNAL(textChanged(const QString&)), 00239 SLOT(slotStepChanged(const QString&))); 00240 connect(editNumber, SIGNAL(textChanged(const QString&)), 00241 SLOT(slotNumberChanged(const QString&))); 00242 00243 /* if(checkSim) 00244 connect(checkSim, SIGNAL(stateChanged(int)), SLOT(slotSetChanged(int))); 00245 connect(checkType, SIGNAL(stateChanged(int)), SLOT(slotSetChanged(int))); 00246 connect(checkParam, SIGNAL(stateChanged(int)), SLOT(slotSetChanged(int))); 00247 connect(checkStart, SIGNAL(stateChanged(int)), SLOT(slotSetChanged(int))); 00248 connect(checkStop, SIGNAL(stateChanged(int)), SLOT(slotSetChanged(int))); 00249 connect(checkNumber, SIGNAL(stateChanged(int)), SLOT(slotSetChanged(int)));*/ 00250 00251 00252 QWidget *tabProperties = new QWidget(t); 00253 t->addTab(tabProperties, tr("Properties")); 00254 //gp1 = new QGridLayout(tabProperties, 9,2,5,5); 00255 gp1 = new QGridLayout(tabProperties); 00256 } 00257 else { // no simulation component 00258 //gp1 = new QGridLayout(0, 9,2,5,5); 00259 gp1 = new QGridLayout(); 00260 all->addLayout(gp1); 00261 } 00262 00263 00264 // ........................................................... 00265 gp1->addWidget(new QLabel(Comp->Description), 0,0,1,2); 00266 00267 QHBoxLayout *h5 = new QHBoxLayout; 00268 h5->setSpacing(5); 00269 00270 h5->addWidget(new QLabel(tr("Name:")) ); 00271 00272 CompNameEdit = new QLineEdit; 00273 h5->addWidget(CompNameEdit); 00274 00275 CompNameEdit->setValidator(ValRestrict); 00276 connect(CompNameEdit, SIGNAL(returnPressed()), SLOT(slotButtOK())); 00277 00278 showName = new QCheckBox(tr("display in schematic")); 00279 h5->addWidget(showName); 00280 00281 QWidget *hTop = new QWidget; 00282 hTop->setLayout(h5); 00283 00284 gp1->addWidget(hTop,1,0); 00285 00286 QGroupBox *PropertyBox = new QGroupBox(tr("Properties")); 00287 gp1->addWidget(PropertyBox,2,0); 00288 00289 // H layout inside the GroupBox 00290 QHBoxLayout *hProps = new QHBoxLayout; 00291 PropertyBox->setLayout(hProps); 00292 00293 // left pane 00294 QWidget *vboxPropsL = new QWidget; 00295 QVBoxLayout *vL = new QVBoxLayout; 00296 vboxPropsL->setLayout(vL); 00297 00299 prop = new QTableWidget(0,4); //initialize 00300 vL->addWidget(prop); 00301 prop->verticalHeader()->setVisible(false); 00302 prop->setSelectionBehavior(QAbstractItemView::SelectRows); 00303 prop->setSelectionMode(QAbstractItemView::SingleSelection); 00304 prop->setMinimumSize(200, 150); 00305 prop->horizontalHeader()->setStretchLastSection(true); 00306 // set automatic resize so all content will be visible, 00307 // horizontal scrollbar will appear if table becomes too large 00308 prop->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents); 00309 prop->horizontalHeader()->setClickable(false); // no action when clicking on the header 00310 00311 connect(prop->horizontalHeader(),SIGNAL(sectionDoubleClicked(int)), 00312 this, SLOT(slotHHeaderClicked(int))); 00313 00314 QStringList headers; 00315 headers << tr("Name") 00316 << tr("Value") 00317 << tr("display") 00318 << tr("Description"); 00319 prop->setHorizontalHeaderLabels(headers); 00320 00321 // right pane 00322 QWidget *vboxPropsR = new QWidget; 00323 QVBoxLayout *v1 = new QVBoxLayout; 00324 vboxPropsR->setLayout(v1); 00325 00326 v1->setSpacing(3); 00327 00328 hProps->addWidget(vboxPropsL, 5); // stretch the left pane (with the table) when resized 00329 hProps->addWidget(vboxPropsR); 00330 00331 Name = new QLabel; 00332 v1->addWidget(Name); 00333 00334 Description = new QLabel; 00335 v1->addWidget(Description); 00336 00337 // hide, because it only replaces 'Description' in some cases 00338 NameEdit = new QLineEdit; 00339 v1->addWidget(NameEdit); 00340 NameEdit->setVisible(false); 00341 NameEdit->setValidator(ValRestrict); 00342 connect(NameEdit, SIGNAL(returnPressed()), SLOT(slotApplyPropName())); 00343 00344 edit = new QLineEdit; 00345 v1->addWidget(edit); 00346 edit->setMinimumWidth(150); 00347 edit->setValidator(Validator2); 00348 connect(edit, SIGNAL(returnPressed()), SLOT(slotApplyProperty())); 00349 00350 // hide, because it only replaces 'edit' in some cases 00351 ComboEdit = new QComboBox; 00352 v1->addWidget(ComboEdit); 00353 ComboEdit->setVisible(false); 00354 connect(ComboEdit, SIGNAL(activated(const QString&)), 00355 SLOT(slotApplyChange(const QString&))); 00356 00357 QHBoxLayout *h3 = new QHBoxLayout; 00358 v1->addLayout(h3); 00359 00360 EditButt = new QPushButton(tr("Edit")); 00361 h3->addWidget(EditButt); 00362 EditButt->setEnabled(false); 00363 EditButt->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); 00364 connect(EditButt, SIGNAL(clicked()), SLOT(slotEditFile())); 00365 00366 BrowseButt = new QPushButton(tr("Browse")); 00367 h3->addWidget(BrowseButt); 00368 BrowseButt->setEnabled(false); 00369 BrowseButt->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); 00370 connect(BrowseButt, SIGNAL(clicked()), SLOT(slotBrowseFile())); 00371 00372 disp = new QCheckBox(tr("display in schematic")); 00373 v1->addWidget(disp); 00374 connect(disp, SIGNAL(stateChanged(int)), SLOT(slotApplyState(int))); 00375 00376 // keep group above together 00377 v1->addStretch(5); 00378 00379 QHBoxLayout *h4 = new QHBoxLayout; 00380 v1->addLayout(h4); 00381 h4->setSpacing(5); 00382 ButtAdd = new QPushButton(tr("Add")); 00383 h4->addWidget(ButtAdd); 00384 ButtAdd->setEnabled(false); 00385 ButtRem = new QPushButton(tr("Remove")); 00386 h4->addWidget(ButtRem); 00387 ButtRem->setEnabled(false); 00388 connect(ButtAdd, SIGNAL(clicked()), SLOT(slotButtAdd())); 00389 connect(ButtRem, SIGNAL(clicked()), SLOT(slotButtRem())); 00390 00391 // Buttons to move equations up/down on the list 00392 QHBoxLayout *hUpDown = new QHBoxLayout; 00393 v1->addLayout(hUpDown); 00394 ButtUp = new QPushButton(tr("Move Up")); 00395 hUpDown->addWidget(ButtUp); 00396 ButtDown = new QPushButton(tr("Move Down")); 00397 hUpDown->addWidget(ButtDown); 00398 connect(ButtUp, SIGNAL(clicked()), SLOT(slotButtUp())); 00399 connect(ButtDown, SIGNAL(clicked()), SLOT(slotButtDown())); 00400 00401 00402 // ........................................................... 00403 QHBoxLayout *h2 = new QHBoxLayout; 00404 QWidget * hbox2 = new QWidget; 00405 hbox2->setLayout(h2); 00406 h2->setSpacing(5); 00407 all->addWidget(hbox2); 00408 QPushButton *ok = new QPushButton(tr("OK")); 00409 QPushButton *apply = new QPushButton(tr("Apply")); 00410 QPushButton *cancel = new QPushButton(tr("Cancel")); 00411 h2->addWidget(ok); 00412 h2->addWidget(apply); 00413 h2->addWidget(cancel); 00414 connect(ok, SIGNAL(clicked()), SLOT(slotButtOK())); 00415 connect(apply, SIGNAL(clicked()), SLOT(slotApplyInput())); 00416 connect(cancel, SIGNAL(clicked()), SLOT(slotButtCancel())); 00417 00418 // ------------------------------------------------------------ 00419 CompNameEdit->setText(Comp->Name); 00420 showName->setChecked(Comp->showName); 00421 changed = false; 00422 00423 Comp->textSize(tx_Dist, ty_Dist); 00424 int tmp = Comp->tx+tx_Dist - Comp->x1; 00425 if((tmp > 0) || (tmp < -6)) tx_Dist = 0; // remember the text position 00426 tmp = Comp->ty+ty_Dist - Comp->y1; 00427 if((tmp > 0) || (tmp < -6)) ty_Dist = 0; 00428 00430 int row=0; // row counter 00431 for(Property *p = Comp->Props.at(Comp->Props.find(pp)+1); p != 0; p = Comp->Props.next()) { 00432 00433 // do not insert if already on first tab 00434 // this is the reason it was originally from back to front... 00435 // the 'pp' is the lasted property stepped over while filling the Swep tab 00436 // if(p == pp) 00437 // break; 00438 if(p->display) 00439 s = tr("yes"); 00440 else 00441 s = tr("no"); 00442 00443 // add Props into TableWidget 00444 qDebug() << " Loading Comp->Props :" << p->Name << p->Value << p->display << p->Description ; 00445 00446 prop->setRowCount(prop->rowCount()+1); 00447 00448 QTableWidgetItem *cell; 00449 cell = new QTableWidgetItem(p->Name); 00450 cell->setFlags(cell->flags() ^ Qt::ItemIsEditable); 00451 prop->setItem(row, 0, cell); 00452 cell = new QTableWidgetItem(p->Value); 00453 cell->setFlags(cell->flags() ^ Qt::ItemIsEditable); 00454 prop->setItem(row, 1, cell); 00455 cell = new QTableWidgetItem(s); 00456 cell->setFlags(cell->flags() ^ Qt::ItemIsEditable); 00457 prop->setItem(row, 2, cell); 00458 cell = new QTableWidgetItem(p->Description); 00459 cell->setFlags(cell->flags() ^ Qt::ItemIsEditable); 00460 prop->setItem(row, 3, cell); 00461 00462 row++; 00463 } 00464 00465 if(prop->rowCount() > 0) { 00466 prop->setCurrentItem(prop->item(0,0)); 00467 slotSelectProperty(prop->item(0,0)); 00468 } 00469 00470 00472 connect(prop, SIGNAL(itemClicked(QTableWidgetItem*)), 00473 SLOT(slotSelectProperty(QTableWidgetItem*))); 00474 } 00475 00476 ComponentDialog::~ComponentDialog() 00477 { 00478 delete all; 00479 delete Validator; 00480 delete Validator2; 00481 delete ValRestrict; 00482 delete ValInteger; 00483 } 00484 00485 // Updates component property list. Useful for MultiViewComponents 00486 void ComponentDialog::updateCompPropsList() 00487 { 00488 int last_prop=0; // last property not to put in ListView 00489 // ........................................................... 00490 // if simulation component: .TR, .AC, .SW, (.SP ?) 00491 if((Comp->Model[0] == '.') && 00492 (Comp->Model != ".DC") && (Comp->Model != ".HB") && 00493 (Comp->Model != ".Digi") && (Comp->Model != ".ETR")) { 00494 if(Comp->Model == ".SW") { // parameter sweep 00495 last_prop = 2; 00496 } else { 00497 last_prop = 0; 00498 } 00499 last_prop += 4; // remember last property for ListView 00500 } 00501 00502 QString s; 00503 int row=0; // row counter 00504 //for(Property *p = Comp->Props.first(); p != 0; p = Comp->Props.next()) { 00505 for(Property *p = Comp->Props.at(last_prop); p != 0; p = Comp->Props.next()) { 00506 00507 // do not insert if already on first tab 00508 // this is the reason it was originally from back to front... 00509 // the 'pp' is the lasted property stepped over while filling the Swep tab 00510 // if(p == pp) 00511 // break; 00512 if(p->display) 00513 s = tr("yes"); 00514 else 00515 s = tr("no"); 00516 00517 // add Props into TableWidget 00518 qDebug() << " Loading Comp->Props :" << p->Name << p->Value << p->display << p->Description ; 00519 00520 if (row > prop->rowCount()-1) { // Add new rows 00521 prop->setRowCount(prop->rowCount()+1); 00522 } 00523 00524 QTableWidgetItem *cell; 00525 cell = new QTableWidgetItem(p->Name); 00526 cell->setFlags(cell->flags() ^ Qt::ItemIsEditable); 00527 prop->setItem(row, 0, cell); 00528 cell = new QTableWidgetItem(p->Value); 00529 cell->setFlags(cell->flags() ^ Qt::ItemIsEditable); 00530 prop->setItem(row, 1, cell); 00531 cell = new QTableWidgetItem(s); 00532 cell->setFlags(cell->flags() ^ Qt::ItemIsEditable); 00533 prop->setItem(row, 2, cell); 00534 cell = new QTableWidgetItem(p->Description); 00535 cell->setFlags(cell->flags() ^ Qt::ItemIsEditable); 00536 prop->setItem(row, 3, cell); 00537 00538 row++; 00539 } 00540 00541 if(prop->rowCount() > 0) { 00542 prop->setCurrentItem(prop->item(0,0)); 00543 slotSelectProperty(prop->item(0,0)); 00544 } 00545 00546 if (row < prop->rowCount()-1) { 00547 prop->setRowCount(row); 00548 } 00549 } 00550 00551 // ------------------------------------------------------------------------- 00552 // Is called if a property is selected. 00553 // Handle the Property editor tab. 00554 // It transfers the values to the right side for editing. 00555 void ComponentDialog::slotSelectProperty(QTableWidgetItem *item) 00556 { 00557 if(item == 0) return; 00558 item->setSelected(true); // if called from elsewhere, this was not yet done 00559 00560 qDebug() << "row " << item->row(); //<< item->text() 00561 00562 QString name = prop->item(item->row(),0)->text(); 00563 QString value = prop->item(item->row(),1)->text(); 00564 QString show = prop->item(item->row(),2)->text(); 00565 QString desc = prop->item(item->row(),3)->text(); 00566 00567 if(show == tr("yes")) 00568 disp->setChecked(true); 00569 else 00570 disp->setChecked(false); 00571 00572 if(name == "File") { 00573 EditButt->setEnabled(true); 00574 BrowseButt->setEnabled(true); 00575 } 00576 else { 00577 EditButt->setEnabled(false); 00578 BrowseButt->setEnabled(false); 00579 } 00580 00583 if(desc.isEmpty()) { 00584 // show two line edit fields (name and value) 00585 ButtAdd->setEnabled(true); 00586 ButtRem->setEnabled(true); 00587 00588 if (Comp->Description == "equation") { 00589 ButtUp->setEnabled(true); 00590 ButtDown->setEnabled(true); 00591 } 00592 else { 00593 ButtUp->setEnabled(false); 00594 ButtDown->setEnabled(false); 00595 } 00596 Name->setText(""); 00597 NameEdit->setText(name); 00598 edit->setText(value); 00599 00600 edit->setVisible(true); 00601 NameEdit->setVisible(true); 00602 Description->setVisible(false); 00603 ComboEdit->setVisible(false); 00604 00605 NameEdit->setFocus(); // edit QLineEdit 00606 } 00607 else { // show standard line edit (description and value) 00608 ButtAdd->setEnabled(false); 00609 ButtRem->setEnabled(false); 00610 ButtUp->setEnabled(false); 00611 ButtDown->setEnabled(false); 00612 00613 Name->setText(name); 00614 edit->setText(value); 00615 00616 NameEdit->setVisible(false); 00617 NameEdit->setText(name); // perhaps used for adding properties 00618 Description->setVisible(true); 00619 00620 // handle special combobox items 00621 QStringList List; 00622 int b = desc.indexOf('['); 00623 int e = desc.lastIndexOf(']'); 00624 if (e-b > 2) { 00625 QString str = desc.mid(b+1, e-b-1); 00626 str.replace( QRegExp("[^a-zA-Z0-9_,]"), "" ); 00627 List = str.split(','); 00628 qDebug() << "List = " << List; 00629 } 00630 00631 // use the screen-compatible metric 00632 QFontMetrics metrics(QucsSettings.font, 0); // get size of text 00633 qDebug() << "desc = " << desc << metrics.width(desc); 00634 while(metrics.width(desc) > 270) { // if description too long, cut it nicely 00635 // so 270 above will be the maximum size of the name label and associated edit line widget 00636 if (desc.lastIndexOf(' ') != -1) 00637 desc = desc.left(desc.lastIndexOf(' ')) + "...."; 00638 else 00639 desc = desc.left(desc.length()-5) + "...."; 00640 } 00641 Description->setText(desc); 00642 00643 if(List.count() >= 1) { // ComboBox with value list or line edit ? 00644 ComboEdit->clear(); 00645 ComboEdit->insertItems(0,List); 00646 00647 for(int i=ComboEdit->count()-1; i>=0; i--) 00648 if(value == ComboEdit->itemText(i)) { 00649 ComboEdit->setCurrentIndex(i); 00650 break; 00651 } 00652 edit->setVisible(false); 00653 ComboEdit->setVisible(true); 00654 } 00655 else { 00656 edit->setVisible(true); 00657 ComboEdit->setVisible(false); 00658 } 00659 edit->setFocus(); // edit QLineEdit 00660 } 00661 } 00662 00663 // ------------------------------------------------------------------------- 00664 void ComponentDialog::slotApplyChange(const QString& Text) 00665 { 00667 // pick selected row 00668 QList<QTableWidgetItem *> items = prop->selectedItems(); 00669 Q_ASSERT(!items.isEmpty()); 00670 QTableWidgetItem *item = items.first(); 00671 00672 int row = item->row(); 00673 00674 edit->setText(Text); 00675 // apply edit line 00676 prop->item(row, 1)->setText(Text); 00677 00678 ComboEdit->setFocus(); 00679 00680 // step to next item if not at the last line 00681 if ( row < (prop->rowCount() - 1)) { 00682 prop->setCurrentItem(prop->item(row+1,0)); 00683 slotSelectProperty(prop->item(row+1,0)); 00684 } 00685 } 00686 00692 void ComponentDialog::slotApplyProperty() 00693 { 00694 // pick selected row 00695 QTableWidgetItem *item = prop->selectedItems()[0]; 00696 00697 int row = item->row(); 00698 00699 QString name = prop->item(row, 0)->text(); 00700 QString value = prop->item(row, 1)->text(); 00701 00702 if(!item) 00703 return; 00704 00705 if (!ComboEdit->isHidden()) // take text from ComboBox ? 00706 edit->setText(ComboEdit->currentText()); 00707 00708 // apply edit line 00709 if(value != edit->text()) { 00710 prop->item(row, 1)->setText(edit->text()); 00711 } 00712 00713 if (!NameEdit->isHidden()) // also apply property name ? 00714 if (name != NameEdit->text()) { 00715 // if(NameEdit->text() == "Export") 00716 // item->setText(0, "Export_"); // name must not be "Export" !!! 00717 // else 00718 // item->setText(0, NameEdit->text()); // apply property name 00719 prop->item(row, 0)->setText(edit->text()); 00720 } 00721 00722 // step to next item 00723 if ( row < prop->rowCount()) { 00724 prop->setCurrentItem(prop->item(row+1,0)); 00725 slotSelectProperty(prop->item(row+1,0)); 00726 } 00727 else { 00728 slotButtOK(); // close dialog, if it was the last property 00729 return; 00730 } 00731 } 00732 00733 // ------------------------------------------------------------------------- 00734 // Is called if the "RETURN"-button is pressed in the "NameEdit" Widget. 00735 void ComponentDialog::slotApplyPropName() 00736 { 00737 // pick selected row 00738 QTableWidgetItem *item = prop->selectedItems()[0]; 00739 int row = item->row(); 00740 00741 QString name = prop->item(row, 0)->text(); 00742 00743 if(name != NameEdit->text()) { 00744 // if(NameEdit->text() == "Export") { 00745 // item->setText(0, "Export_"); // name must not be "Export" !!! 00746 // NameEdit->setText("Export_"); 00747 // } 00748 // else 00749 prop->item(row, 0)->setText(NameEdit->text()); 00750 } 00751 edit->setFocus(); // cursor into "edit" widget 00752 } 00753 00754 // ------------------------------------------------------------------------- 00755 // Is called if the checkbox is pressed (changed). 00756 void ComponentDialog::slotApplyState(int State) 00757 { 00758 // pick selected row 00759 QTableWidgetItem *item = prop->selectedItems()[0]; 00760 int row = item->row(); 00761 00762 QString disp = prop->item(row, 2)->text(); 00763 00764 if(item == 0) return; 00765 00766 QString ButtonState; 00767 if(State) 00768 ButtonState = tr("yes"); 00769 else 00770 ButtonState = tr("no"); 00771 00772 if(disp != ButtonState) { 00773 prop->item(row, 2)->setText(ButtonState); 00774 } 00775 } 00776 00777 // ------------------------------------------------------------------------- 00778 // Is called if the "OK"-button is pressed. 00779 void ComponentDialog::slotButtOK() 00780 { 00781 slotApplyInput(); 00782 slotButtCancel(); 00783 } 00784 00785 // ------------------------------------------------------------------------- 00786 // Is called if the "Cancel"-button is pressed. 00787 void ComponentDialog::slotButtCancel() 00788 { 00789 if(changed) done(1); // changed could have been done before 00790 else done(0); // (by "Apply"-button) 00791 } 00792 00793 //----------------------------------------------------------------- 00794 // To get really all close events (even <Escape> key). 00795 void ComponentDialog::reject() 00796 { 00797 slotButtCancel(); 00798 } 00799 00800 // ------------------------------------------------------------------------- 00801 // Is called, if the "Apply"-button is pressed. 00802 void ComponentDialog::slotApplyInput() 00803 { 00804 qDebug() << " \n == Apply "; 00805 if(Comp->showName != showName->isChecked()) { 00806 Comp->showName = showName->isChecked(); 00807 changed = true; 00808 } 00809 00810 QString tmp; 00811 Component *pc; 00812 if(CompNameEdit->text().isEmpty()) CompNameEdit->setText(Comp->Name); 00813 else 00814 if(CompNameEdit->text() != Comp->Name) { 00815 for(pc = Doc->Components->first(); pc!=0; pc = Doc->Components->next()) 00816 if(pc->Name == CompNameEdit->text()) 00817 break; // found component with the same name ? 00818 if(pc) CompNameEdit->setText(Comp->Name); 00819 else { 00820 Comp->Name = CompNameEdit->text(); 00821 changed = true; 00822 } 00823 } 00824 00830 bool display; 00831 Property *pp = Comp->Props.first(); 00832 // apply all the new property values 00833 00834 if(comboSim) { 00835 display = checkSim->isChecked(); 00836 if(pp->display != display) { 00837 pp->display = display; 00838 changed = true; 00839 } 00840 if(pp->Value != comboSim->currentText()) { 00841 pp->Value = comboSim->currentText(); 00842 changed = true; 00843 } 00844 pp = Comp->Props.next(); 00845 } 00846 if(comboType) { 00847 display = checkType->isChecked(); 00848 if(pp->display != display) { 00849 pp->display = display; 00850 changed = true; 00851 } 00852 switch(comboType->currentIndex()) { 00853 case 1: tmp = "log"; break; 00854 case 2: tmp = "list"; break; 00855 case 3: tmp = "const"; break; 00856 default: tmp = "lin"; break; 00857 } 00858 if(pp->Value != tmp) { 00859 pp->Value = tmp; 00860 changed = true; 00861 } 00862 pp = Comp->Props.next(); 00863 } 00864 if(checkParam) if(checkParam->isEnabled()) { 00865 display = checkParam->isChecked(); 00866 if(pp->display != display) { 00867 pp->display = display; 00868 changed = true; 00869 } 00870 if(pp->Value != editParam->text()) { 00871 pp->Value = editParam->text(); 00872 changed = true; 00873 } 00874 pp = Comp->Props.next(); 00875 } 00876 if(editStart) { 00877 if(comboType->currentIndex() < 2) { 00878 display = checkStart->isChecked(); 00879 if(pp->display != display) { 00880 pp->display = display; 00881 changed = true; 00882 } 00883 pp->Name = "Start"; 00884 if(pp->Value != editStart->text()) { 00885 pp->Value = editStart->text(); 00886 changed = true; 00887 } 00888 pp = Comp->Props.next(); 00889 00890 display = checkStop->isChecked(); 00891 if(pp->display != display) { 00892 pp->display = display; 00893 changed = true; 00894 } 00895 pp->Name = "Stop"; 00896 if(pp->Value != editStop->text()) { 00897 pp->Value = editStop->text(); 00898 changed = true; 00899 } 00900 pp = Comp->Props.next(); 00901 00902 display = checkNumber->isChecked(); 00903 if(pp->display != display) { 00904 pp->display = display; 00905 changed = true; 00906 } 00907 if((pp->Value != editNumber->text()) || (pp->Name != "Points")) { 00908 pp->Value = editNumber->text(); 00909 pp->Name = "Points"; 00910 changed = true; 00911 } 00912 qDebug() << "====> before ad" 00913 << pp->Description; 00914 00915 pp = Comp->Props.next(); 00916 } 00917 else { 00918 // If a value list is used, the properties "Start" and "Stop" are not 00919 // used. -> Call them "Symbol" to omit them in the netlist. 00920 pp->Name = "Symbol"; 00921 pp->display = false; 00922 pp = Comp->Props.next(); 00923 pp->Name = "Symbol"; 00924 pp->display = false; 00925 pp = Comp->Props.next(); 00926 00927 display = checkValues->isChecked(); 00928 if(pp->display != display) { 00929 pp->display = display; 00930 changed = true; 00931 } 00932 tmp = "["+editValues->text()+"]"; 00933 if((pp->Value != tmp) || (pp->Name != "Values")) { 00934 pp->Value = tmp; 00935 pp->Name = "Values"; 00936 changed = true; 00937 } 00938 qDebug() << "====> before ad" 00939 << pp; 00940 00941 pp = Comp->Props.next(); 00942 } 00943 } 00944 00945 00946 // pick selected row 00947 QTableWidgetItem *item = 0; 00948 00949 // make sure we have one item, take selected 00950 if (prop->selectedItems().size()) { 00951 item = prop->selectedItems()[0]; 00952 } 00953 00956 if(item != 0) { 00957 int row = item->row(); 00958 QString name = prop->item(row, 0)->text(); 00959 QString value = prop->item(row, 1)->text(); 00960 00961 // apply edit line 00962 if(value != edit->text()) 00963 prop->item(row, 1)->setText(edit->text()); 00964 00965 // apply property name 00966 if (!NameEdit->isHidden()) 00967 if (name != NameEdit->text()) 00968 prop->item(row, 0)->setText(NameEdit->text()); 00969 00970 // apply all the new property values in the ListView 00971 for( int row = 0; row < prop->rowCount(); row++ ) { 00972 00973 QString name = prop->item(row, 0)->text(); 00974 QString value = prop->item(row, 1)->text(); 00975 QString disp = prop->item(row, 2)->text(); 00976 QString desc = prop->item(row, 3)->text(); 00977 00978 qDebug() << "====>" <<name << value 00979 << Comp->Props.count() 00980 << prop->rowCount() +1 00981 << pp; 00982 00983 display = (disp == tr("yes")); 00984 if( pp ) { 00985 00986 if(pp->display != display) { 00987 pp->display = display; 00988 changed = true; 00989 } 00990 if(pp->Value != value) { 00991 pp->Value = value; 00992 changed = true; 00993 } 00994 if(pp->Name != name) { 00995 pp->Name = name; // override if previous one was removed 00996 changed = true; 00997 } 00998 pp->Description = desc; 00999 } 01000 else { 01001 // if properties where added in the dialog 01002 // -> create new on the Comp 01003 Q_ASSERT(prop->rowCount() >= 0); 01004 if ( (int) Comp->Props.count() < prop->rowCount() +1) { 01005 qDebug() << "adding to Comp "; 01006 Comp->Props.append(new Property(name, value, display, desc)); 01007 changed = true; 01008 } 01009 } 01010 pp = Comp->Props.next(); 01011 } 01012 01013 // original Comp still has properties? (removed some in the dialog?) 01014 // if more properties than in ListView -> delete the rest 01015 if(pp) { 01016 pp = Comp->Props.prev(); 01017 Comp->Props.last(); 01018 while(pp != Comp->Props.current()) 01019 Comp->Props.remove(); 01020 changed = true; 01021 } 01022 01023 } // end if (item !=0) 01024 01025 if(changed) { 01026 int dx, dy; 01027 Comp->textSize(dx, dy); 01028 if(tx_Dist != 0) { 01029 Comp->tx += tx_Dist-dx; 01030 tx_Dist = dx; 01031 } 01032 if(ty_Dist != 0) { 01033 Comp->ty += ty_Dist-dy; 01034 ty_Dist = dy; 01035 } 01036 01037 Doc->recreateComponent(Comp); 01038 Doc->viewport()->repaint(); 01039 if ( (int) Comp->Props.count() != prop->rowCount()) { // If props count was changed after recreation 01040 Q_ASSERT(prop->rowCount() >= 0); 01041 updateCompPropsList(); // of component we need to update properties 01042 } 01043 } 01044 01045 } 01046 01047 // ------------------------------------------------------------------------- 01048 void ComponentDialog::slotBrowseFile() 01049 { 01050 // current file name from the component properties 01051 QString currFileName = prop->item(prop->currentRow(), 1)->text(); 01052 QFileInfo currFileInfo(currFileName); 01053 // name of the schematic where component is instantiated (may be empty) 01054 QFileInfo schematicFileInfo = Comp->getSchematic()->getFileInfo(); 01055 QString schematicFileName = schematicFileInfo.fileName(); 01056 // directory to use for the file open dialog 01057 QString currDir; 01058 01059 if (!currFileName.isEmpty()) { // a file name is already defined 01060 if (currFileInfo.isRelative()) { // but has no absolute path 01061 if (!schematicFileName.isEmpty()) { // if schematic has a filename 01062 // build the an absolute file name using the schematic path 01063 currDir = schematicFileInfo.absolutePath() + 01064 QDir::separator() + 01065 currFileInfo.fileName(); 01066 } else { // no absolute paths around 01067 // use the WorkDir path 01068 currDir = QucsSettings.QucsWorkDir.path() + 01069 QDir::separator() + 01070 currFileInfo.fileName(); 01071 } 01072 } else { // current file name is absolute 01073 // use it 01074 currDir = currFileName; 01075 } 01076 } else { // a file name is not defined 01077 if (!schematicFileName.isEmpty()) { // if schematic has a filename 01078 // use the schematic absolute path 01079 currDir = schematicFileInfo.absolutePath(); 01080 } else { // no absolute paths around 01081 // use the WorkDir path 01082 currDir = QucsSettings.QucsWorkDir.path(); 01083 } 01084 } 01085 01086 QString s = QFileDialog::getOpenFileName ( 01087 this, 01088 tr("Select a file"), 01089 currDir, 01090 tr("All Files")+" (*.*);;" 01091 + tr("Touchstone files") + " (*.s?p);;" 01092 + tr("CSV files") + " (*.csv);;" 01093 + tr("SPICE files") + " (*.cir *.spi);;" 01094 + tr("VHDL files") + " (*.vhdl *.vhd);;" 01095 + tr("Verilog files")+" (*.v)" ); 01096 01097 if(!s.isEmpty()) { 01098 // snip path if file in current directory 01099 QFileInfo file(s); 01100 if(QucsSettings.QucsWorkDir.exists(file.fileName()) && 01101 QucsSettings.QucsWorkDir.absolutePath() == file.absolutePath()) s = file.fileName(); 01102 edit->setText(s); 01103 } 01104 /* FIX 01105 prop->currentItem()->setText(1, s); */ 01106 } 01107 01108 // ------------------------------------------------------------------------- 01109 void ComponentDialog::slotEditFile() 01110 { 01111 Doc->App->editFile(QucsSettings.QucsWorkDir.filePath(edit->text())); 01112 } 01113 01135 void ComponentDialog::slotButtAdd() 01136 { 01137 // Set existing equation into focus, return 01138 for(int row=0; row < prop->rowCount(); row++) { 01139 QString name = prop->item(row, 0)->text(); 01140 if( name == NameEdit->text()) { 01141 prop->setCurrentItem(prop->item(row,0)); 01142 slotSelectProperty(prop->item(row,0)); 01143 return; 01144 } 01145 } 01146 01147 // toggle display flag 01148 QString s = tr("no"); 01149 if(disp->isChecked()) 01150 s = tr("yes"); 01151 01152 // get number for selected row 01153 int curRow = prop->currentRow(); 01154 01155 // insert new row under current 01156 int insRow = curRow+1; 01157 prop->insertRow(insRow); 01158 01159 // append new row 01160 QTableWidgetItem *cell; 01161 cell = new QTableWidgetItem(NameEdit->text()); 01162 cell->setFlags(cell->flags() ^ Qt::ItemIsEditable); 01163 prop->setItem(insRow, 0, cell); 01164 cell = new QTableWidgetItem(edit->text()); 01165 cell->setFlags(cell->flags() ^ Qt::ItemIsEditable); 01166 prop->setItem(insRow, 1, cell); 01167 cell = new QTableWidgetItem(s); 01168 cell->setFlags(cell->flags() ^ Qt::ItemIsEditable); 01169 prop->setItem(insRow, 2, cell); 01170 // no description? add empty cell 01171 cell = new QTableWidgetItem(""); 01172 cell->setFlags(cell->flags() ^ Qt::ItemIsEditable); 01173 prop->setItem(insRow, 3, cell); 01174 01175 // select new row 01176 prop->selectRow(insRow); 01177 } 01178 01185 void ComponentDialog::slotButtRem() 01186 { 01187 if(prop->rowCount() < 3) 01188 return; // the last property cannot be removed 01189 01190 QTableWidgetItem *item = prop->selectedItems()[0]; 01191 int row = item->row(); 01192 01193 if(item == 0) 01194 return; 01195 01196 // peek next, delete current, set next current 01197 if ( row < prop->rowCount()) { 01198 prop->setCurrentItem(prop->item(row+1,0)); 01199 slotSelectProperty(prop->item(row+1,0)); 01200 prop->removeRow(row); 01201 } 01202 } 01203 01208 void ComponentDialog::slotButtUp() 01209 { 01210 qDebug() << "slotButtUp" << prop->currentRow() << prop->rowCount(); 01211 01212 int curRow = prop->currentRow(); 01213 if (curRow == 0) 01214 return; 01215 01216 // swap current and row above it 01217 QTableWidgetItem *source = prop->takeItem(curRow ,0); 01218 QTableWidgetItem *target = prop->takeItem(curRow-1,0); 01219 prop->setItem(curRow-1, 0, source); 01220 prop->setItem(curRow, 0, target); 01221 source = prop->takeItem(curRow ,1); 01222 target = prop->takeItem(curRow-1,1); 01223 prop->setItem(curRow-1, 1, source); 01224 prop->setItem(curRow, 1, target); 01225 01226 01227 // select moved row 01228 prop->selectRow(curRow-1); 01229 } 01230 01235 void ComponentDialog::slotButtDown() 01236 { 01237 qDebug() << "slotButtDown" << prop->currentRow() << prop->rowCount(); 01238 01239 int curRow = prop->currentRow(); 01240 // Leave Export as last 01241 if (curRow == prop->rowCount()-2) 01242 return; 01243 01244 // swap current and row below it 01245 QTableWidgetItem *source = prop->takeItem(curRow,0); 01246 QTableWidgetItem *target = prop->takeItem(curRow+1,0); 01247 prop->setItem(curRow+1, 0, source); 01248 prop->setItem(curRow, 0, target); 01249 source = prop->takeItem(curRow,1); 01250 target = prop->takeItem(curRow+1,1); 01251 prop->setItem(curRow+1, 1, source); 01252 prop->setItem(curRow, 1, target); 01253 01254 // select moved row 01255 prop->selectRow(curRow+1); 01256 } 01257 01258 // ------------------------------------------------------------------------- 01259 void ComponentDialog::slotSimTypeChange(int Type) 01260 { 01261 if(Type < 2) { // new type is "linear" or "logarithmic" 01262 if(!editNumber->isEnabled()) { // was the other mode before ? 01263 // this text change, did not emit the textChange signal !??! 01264 editStart->setText( 01265 editValues->text().section(';', 0, 0).trimmed()); 01266 editStop->setText( 01267 editValues->text().section(';', -1, -1).trimmed()); 01268 editNumber->setText("2"); 01269 slotNumberChanged(0); 01270 01271 checkStart->setChecked(true); 01272 checkStop->setChecked(true); 01273 } 01274 textValues->setDisabled(true); 01275 editValues->setDisabled(true); 01276 checkValues->setDisabled(true); 01277 textStart->setDisabled(false); 01278 editStart->setDisabled(false); 01279 checkStart->setDisabled(false); 01280 textStop->setDisabled(false); 01281 editStop->setDisabled(false); 01282 checkStop->setDisabled(false); 01283 textStep->setDisabled(false); 01284 editStep->setDisabled(false); 01285 textNumber->setDisabled(false); 01286 editNumber->setDisabled(false); 01287 checkNumber->setDisabled(false); 01288 if(Type == 1) // logarithmic ? 01289 textStep->setText(tr("Points per decade:")); 01290 else 01291 textStep->setText(tr("Step:")); 01292 } 01293 else { // new type is "list" or "constant" 01294 if(!editValues->isEnabled()) { // was the other mode before ? 01295 editValues->setText(editStart->text() + "; " + editStop->text()); 01296 checkValues->setChecked(true); 01297 } 01298 01299 textValues->setDisabled(false); 01300 editValues->setDisabled(false); 01301 checkValues->setDisabled(false); 01302 textStart->setDisabled(true); 01303 editStart->setDisabled(true); 01304 checkStart->setDisabled(true); 01305 textStop->setDisabled(true); 01306 editStop->setDisabled(true); 01307 checkStop->setDisabled(true); 01308 textStep->setDisabled(true); 01309 editStep->setDisabled(true); 01310 textNumber->setDisabled(true); 01311 editNumber->setDisabled(true); 01312 checkNumber->setDisabled(true); 01313 textStep->setText(tr("Step:")); 01314 } 01315 } 01316 01317 // ------------------------------------------------------------------------- 01318 // Is called when "Start", "Stop" or "Number" is edited. 01319 void ComponentDialog::slotNumberChanged(const QString&) 01320 { 01321 QString Unit, tmp; 01322 double x, y, Factor; 01323 if(comboType->currentIndex() == 1) { // logarithmic ? 01324 misc::str2num(editStop->text(), x, Unit, Factor); 01325 x *= Factor; 01326 misc::str2num(editStart->text(), y, Unit, Factor); 01327 y *= Factor; 01328 if(y == 0.0) y = x / 10.0; 01329 if(x == 0.0) x = y * 10.0; 01330 if(y == 0.0) { y = 1.0; x = 10.0; } 01331 x = editNumber->text().toDouble() / log10(fabs(x / y)); 01332 Unit = QString::number(x); 01333 } 01334 else { 01335 misc::str2num(editStop->text(), x, Unit, Factor); 01336 x *= Factor; 01337 misc::str2num(editStart->text(), y, Unit, Factor); 01338 y *= Factor; 01339 x = (x - y) / (editNumber->text().toDouble() - 1.0); 01340 01341 QString step = misc::num2str(x); 01342 01343 misc::str2num(step, x, Unit, Factor); 01344 if(Factor == 1.0) 01345 Unit = ""; 01346 01347 Unit = QString::number(x) + " " + Unit; 01348 } 01349 01350 editStep->blockSignals(true); // do not calculate step again 01351 editStep->setText(Unit); 01352 editStep->blockSignals(false); 01353 } 01354 01355 // ------------------------------------------------------------------------- 01356 void ComponentDialog::slotStepChanged(const QString& Step) 01357 { 01358 QString Unit; 01359 double x, y, Factor; 01360 if(comboType->currentIndex() == 1) { // logarithmic ? 01361 misc::str2num(editStop->text(), x, Unit, Factor); 01362 x *= Factor; 01363 misc::str2num(editStart->text(), y, Unit, Factor); 01364 y *= Factor; 01365 01366 x /= y; 01367 misc::str2num(Step, y, Unit, Factor); 01368 y *= Factor; 01369 01370 x = log10(fabs(x)) * y; 01371 } 01372 else { 01373 misc::str2num(editStop->text(), x, Unit, Factor); 01374 x *= Factor; 01375 misc::str2num(editStart->text(), y, Unit, Factor); 01376 y *= Factor; 01377 01378 x -= y; 01379 misc::str2num(Step, y, Unit, Factor); 01380 y *= Factor; 01381 01382 x /= y; 01383 } 01384 01385 editNumber->blockSignals(true); // do not calculate number again 01386 editNumber->setText(QString::number(floor(x + 1.0))); 01387 editNumber->blockSignals(false); 01388 } 01389 01390 // ------------------------------------------------------------------------- 01391 // Is called if return is pressed in LineEdit "Parameter". 01392 void ComponentDialog::slotParamEntered() 01393 { 01394 if(editValues->isEnabled()) 01395 editValues->setFocus(); 01396 else 01397 editStart->setFocus(); 01398 } 01399 01400 // ------------------------------------------------------------------------- 01401 // Is called if return is pressed in LineEdit "Simulation". 01402 void ComponentDialog::slotSimEntered(int) 01403 { 01404 editParam->setFocus(); 01405 } 01406 01407 // ------------------------------------------------------------------------- 01408 // Is called if return is pressed in LineEdit "Values". 01409 void ComponentDialog::slotValuesEntered() 01410 { 01411 slotButtOK(); 01412 } 01413 01414 // ------------------------------------------------------------------------- 01415 // Is called if return is pressed in LineEdit "Start". 01416 void ComponentDialog::slotStartEntered() 01417 { 01418 editStop->setFocus(); 01419 } 01420 01421 // ------------------------------------------------------------------------- 01422 // Is called if return is pressed in LineEdit "Stop". 01423 void ComponentDialog::slotStopEntered() 01424 { 01425 editStep->setFocus(); 01426 } 01427 01428 // ------------------------------------------------------------------------- 01429 // Is called if return is pressed in LineEdit "Step". 01430 void ComponentDialog::slotStepEntered() 01431 { 01432 editNumber->setFocus(); 01433 } 01434 01435 // ------------------------------------------------------------------------- 01436 // Is called if return is pressed in LineEdit "Number". 01437 void ComponentDialog::slotNumberEntered() 01438 { 01439 slotButtOK(); 01440 } 01441 01442 // if clicked on 'display' header toggle visibility for all items 01443 void ComponentDialog::slotHHeaderClicked(int headerIdx) 01444 { 01445 if (headerIdx != 2) return; // clicked on header other than 'display' 01446 01447 QString s; 01448 QTableWidgetItem *cell; 01449 01450 if (setAllVisible) 01451 s = tr("yes"); 01452 else 01453 s = tr("no"); 01454 01455 // go through all the properties table and set the visibility cell 01456 for (int row = 0; row < prop->rowCount(); row++) { 01457 cell = prop->item(row, 2); 01458 cell->setText(s); 01459 } 01460 setAllVisible = not setAllVisible; // toggle visibility for the next double-click 01461 }