26 #include <qhgroupbox.h>
27 #include <qvalidator.h>
28 #include <qtabwidget.h>
29 #include <qfiledialog.h>
35 : QDialog(d, 0, TRUE, Qt::WDestructiveClose)
38 setCaption(tr(
"Edit Component Properties"));
43 all =
new QVBoxLayout(
this);
45 QWidget *myParent =
this;
46 ValInteger =
new QIntValidator(1, 1000000,
this);
48 Expr.setPattern(
"[^\"=]*");
49 Validator =
new QRegExpValidator(Expr,
this);
50 Expr.setPattern(
"[^\"]*");
51 Validator2 =
new QRegExpValidator(Expr,
this);
52 Expr.setPattern(
"[\\w_]+");
53 ValRestrict =
new QRegExpValidator(Expr,
this);
55 checkSim = 0; editSim = 0; comboType = 0; checkParam = 0;
56 editStart = 0; editStop = 0; editNumber = 0;
61 if((Comp->
Model[0] ==
'.') &&
62 (Comp->
Model !=
".DC") && (Comp->
Model !=
".HB") &&
63 (Comp->
Model !=
".Digi")) {
64 QTabWidget *
t =
new QTabWidget(
this);
67 QWidget *Tab1 =
new QWidget(t);
68 t->addTab(Tab1, tr(
"Sweep"));
69 QGridLayout *gp =
new QGridLayout(Tab1, 9,3,5,5);
71 gp->addMultiCellWidget(
new QLabel(Comp->
Description, Tab1), 0,0,0,1);
74 editParam =
new QLineEdit(Tab1);
75 editParam->setValidator(ValRestrict);
76 connect(editParam, SIGNAL(returnPressed()), SLOT(slotParamEntered()));
77 checkParam =
new QCheckBox(tr(
"display in schematic"), Tab1);
78 if(Comp->
Model ==
".SW") {
79 textSim =
new QLabel(tr(
"Simulation:"), Tab1);
80 gp->addWidget(textSim, row,0);
81 editSim =
new QComboBox(Tab1);
82 editSim->setEditable(
true);
83 connect(editSim, SIGNAL(activated(
int)), SLOT(slotSimEntered(
int)));
84 gp->addWidget(editSim, row,1);
85 checkSim =
new QCheckBox(tr(
"display in schematic"), Tab1);
86 gp->addWidget(checkSim, row++,2);
89 editParam->setReadOnly(
true);
90 checkParam->setDisabled(
true);
91 if(Comp->
Model ==
".TR")
92 editParam->setText(
"time");
94 if(Comp->
Model ==
".AC")
95 editParam->setText(
"acfrequency");
97 editParam->setText(
"frequency");
101 gp->addWidget(
new QLabel(tr(
"Sweep Parameter:"), Tab1), row,0);
102 gp->addWidget(editParam, row,1);
103 gp->addWidget(checkParam, row++,2);
105 textType =
new QLabel(tr(
"Type:"), Tab1);
106 gp->addWidget(textType, row,0);
107 comboType =
new QComboBox(Tab1);
108 comboType->insertItem(tr(
"linear"));
109 comboType->insertItem(tr(
"logarithmic"));
110 comboType->insertItem(tr(
"list"));
111 comboType->insertItem(tr(
"constant"));
112 gp->addWidget(comboType, row,1);
113 connect(comboType, SIGNAL(activated(
int)), SLOT(slotSimTypeChange(
int)));
114 checkType =
new QCheckBox(tr(
"display in schematic"), Tab1);
115 gp->addWidget(checkType, row++,2);
117 textValues =
new QLabel(tr(
"Values:"), Tab1);
118 gp->addWidget(textValues, row,0);
119 editValues =
new QLineEdit(Tab1);
120 editValues->setValidator(Validator);
121 connect(editValues, SIGNAL(returnPressed()), SLOT(slotValuesEntered()));
122 gp->addWidget(editValues, row,1);
123 checkValues =
new QCheckBox(tr(
"display in schematic"), Tab1);
124 gp->addWidget(checkValues, row++,2);
126 textStart =
new QLabel(tr(
"Start:"), Tab1);
127 gp->addWidget(textStart, row,0);
128 editStart =
new QLineEdit(Tab1);
129 editStart->setValidator(Validator);
130 connect(editStart, SIGNAL(returnPressed()), SLOT(slotStartEntered()));
131 gp->addWidget(editStart, row,1);
132 checkStart =
new QCheckBox(tr(
"display in schematic"), Tab1);
133 gp->addWidget(checkStart, row++,2);
135 textStop =
new QLabel(tr(
"Stop:"), Tab1);
136 gp->addWidget(textStop, row,0);
137 editStop =
new QLineEdit(Tab1);
138 editStop->setValidator(Validator);
139 connect(editStop, SIGNAL(returnPressed()), SLOT(slotStopEntered()));
140 gp->addWidget(editStop, row,1);
141 checkStop =
new QCheckBox(tr(
"display in schematic"), Tab1);
142 gp->addWidget(checkStop, row++,2);
144 textStep =
new QLabel(tr(
"Step:"), Tab1);
145 gp->addWidget(textStep, row,0);
146 editStep =
new QLineEdit(Tab1);
147 editStep->setValidator(Validator);
148 connect(editStep, SIGNAL(returnPressed()), SLOT(slotStepEntered()));
149 gp->addWidget(editStep, row++,1);
151 textNumber =
new QLabel(tr(
"Number:"), Tab1);
152 gp->addWidget(textNumber, row,0);
153 editNumber =
new QLineEdit(Tab1);
154 editNumber->setValidator(ValInteger);
155 connect(editNumber, SIGNAL(returnPressed()), SLOT(slotNumberEntered()));
156 gp->addWidget(editNumber, row,1);
157 checkNumber =
new QCheckBox(tr(
"display in schematic"), Tab1);
158 gp->addWidget(checkNumber, row++,2);
161 if(Comp->
Model ==
".SW") {
165 if(pc->
Model[0] ==
'.')
166 editSim->insertItem(pc->
Name);
167 editSim->setCurrentText(Comp->
Props.first()->Value);
169 checkSim->setChecked(Comp->
Props.current()->display);
170 s = Comp->
Props.next()->Value;
171 checkType->setChecked(Comp->
Props.current()->display);
172 editParam->setText(Comp->
Props.next()->Value);
173 checkParam->setChecked(Comp->
Props.current()->display);
176 s = Comp->
Props.first()->Value;
177 checkType->setChecked(Comp->
Props.current()->display);
179 pp = Comp->
Props.next();
180 editStart->setText(pp->
Value);
181 checkStart->setChecked(pp->
display);
182 pp = Comp->
Props.next();
183 editStop->setText(pp->
Value);
184 checkStop->setChecked(pp->
display);
185 pp = Comp->
Props.next();
186 editNumber->setText(pp->
Value);
187 checkNumber->setChecked(pp->
display);
198 comboType->setCurrentItem(tNum);
200 slotSimTypeChange(tNum);
203 editNumber->text().mid(1, editNumber->text().length()-2));
204 checkValues->setChecked(Comp->
Props.current()->display);
205 editNumber->setText(
"2");
207 slotNumberChanged(0);
211 connect(editStart, SIGNAL(textChanged(
const QString&)),
212 SLOT(slotNumberChanged(
const QString&)));
213 connect(editStop, SIGNAL(textChanged(
const QString&)),
214 SLOT(slotNumberChanged(
const QString&)));
215 connect(editStep, SIGNAL(textChanged(
const QString&)),
216 SLOT(slotStepChanged(
const QString&)));
217 connect(editNumber, SIGNAL(textChanged(
const QString&)),
218 SLOT(slotNumberChanged(
const QString&)));
229 QWidget *Tab2 =
new QWidget(t);
230 t->addTab(Tab2, tr(
"Properties"));
231 gp1 =
new QGridLayout(Tab2, 9,2,5,5);
235 gp1 =
new QGridLayout(0, 9,2,5,5);
241 gp1->addMultiCellWidget(
new QLabel(Comp->
Description, myParent), 0,0,0,1);
243 QHBox *h5 =
new QHBox(myParent);
245 gp1->addWidget(h5, 1,0);
246 new QLabel(tr(
"Name:"), h5);
247 CompNameEdit =
new QLineEdit(h5);
248 CompNameEdit->setValidator(ValRestrict);
249 connect(CompNameEdit, SIGNAL(returnPressed()), SLOT(slotButtOK()));
251 showName =
new QCheckBox(tr(
"display in schematic"), myParent);
252 gp1->addWidget(showName, 1,1);
254 QHGroupBox *PropertyBox =
new QHGroupBox(tr(
"Properties"), myParent);
255 gp1->addMultiCellWidget(PropertyBox, 2,2,0,1);
257 prop =
new QListView(PropertyBox);
258 prop->setMinimumSize(200, 150);
259 prop->addColumn(tr(
"Name"));
260 prop->addColumn(tr(
"Value"));
261 prop->addColumn(tr(
"display"));
262 prop->addColumn(tr(
"Description"));
263 prop->setSorting(-1);
265 QVBox *v1 =
new QVBox(PropertyBox);
268 Name =
new QLabel(v1);
270 Description =
new QLabel(v1);
273 NameEdit =
new QLineEdit(v1);
274 NameEdit->setShown(
false);
275 NameEdit->setValidator(ValRestrict);
276 connect(NameEdit, SIGNAL(returnPressed()), SLOT(slotApplyPropName()));
278 edit =
new QLineEdit(v1);
279 edit->setMinimumWidth(150);
280 edit->setValidator(Validator2);
281 connect(edit, SIGNAL(returnPressed()), SLOT(slotApplyProperty()));
284 ComboEdit =
new QComboBox(
false, v1);
285 ComboEdit->setShown(
false);
286 connect(ComboEdit, SIGNAL(activated(
const QString&)),
287 SLOT(slotApplyChange(
const QString&)));
289 QHBox *h3 =
new QHBox(v1);
290 h3->setStretchFactor(
new QWidget(h3),5);
291 EditButt =
new QPushButton(tr(
"Edit"),h3);
292 EditButt->setEnabled(
false);
293 EditButt->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
294 connect(EditButt, SIGNAL(clicked()), SLOT(slotEditFile()));
295 BrowseButt =
new QPushButton(tr(
"Browse"),h3);
296 BrowseButt->setEnabled(
false);
297 BrowseButt->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
298 connect(BrowseButt, SIGNAL(clicked()), SLOT(slotBrowseFile()));
300 disp =
new QCheckBox(tr(
"display in schematic"), v1);
301 connect(disp, SIGNAL(stateChanged(
int)), SLOT(slotApplyState(
int)));
303 v1->setStretchFactor(
new QWidget(v1),5);
305 QHBox *h4 =
new QHBox(v1);
307 ButtAdd =
new QPushButton(tr(
"Add"),h4);
308 ButtAdd->setEnabled(
false);
309 ButtRem =
new QPushButton(tr(
"Remove"),h4);
310 ButtRem->setEnabled(
false);
311 connect(ButtAdd, SIGNAL(clicked()), SLOT(slotButtAdd()));
312 connect(ButtRem, SIGNAL(clicked()), SLOT(slotButtRem()));
315 QHBox *h2 =
new QHBox(
this);
318 connect(
new QPushButton(tr(
"OK"),h2), SIGNAL(clicked()),
320 connect(
new QPushButton(tr(
"Apply"),h2), SIGNAL(clicked()),
321 SLOT(slotApplyInput()));
322 connect(
new QPushButton(tr(
"Cancel"),h2), SIGNAL(clicked()),
323 SLOT(slotButtCancel()));
326 CompNameEdit->setText(Comp->
Name);
327 showName->setChecked(Comp->
showName);
331 int tmp = Comp->
tx+tx_Dist - Comp->
x1;
332 if((tmp > 0) || (tmp < -6)) tx_Dist = 0;
333 tmp = Comp->
ty+ty_Dist - Comp->
y1;
334 if((tmp > 0) || (tmp < -6)) ty_Dist = 0;
339 if(p->display) s = tr(
"yes");
341 new QListViewItem(prop, p->Name, p->Value, s, p->Description);
344 if(prop->childCount() > 0) {
345 prop->setCurrentItem(prop->firstChild());
346 slotSelectProperty(prop->firstChild());
349 connect(prop, SIGNAL(clicked(QListViewItem*)),
350 SLOT(slotSelectProperty(QListViewItem*)));
365 void ComponentDialog::slotSelectProperty(QListViewItem *item)
367 if(item == 0)
return;
368 item->setSelected(
true);
370 if(item->text(2) == tr(
"yes")) disp->setChecked(
true);
371 else disp->setChecked(
false);
373 if(item->text(0) ==
"File") {
374 EditButt->setEnabled(
true);
375 BrowseButt->setEnabled(
true);
378 EditButt->setEnabled(
false);
379 BrowseButt->setEnabled(
false);
382 QString PropDesc = item->text(3);
383 if(PropDesc.isEmpty()) {
385 ButtAdd->setEnabled(
true);
386 ButtRem->setEnabled(
true);
389 NameEdit->setText(item->text(0));
390 edit->setText(item->text(1));
392 edit->setShown(
true);
393 NameEdit->setShown(
true);
394 Description->setShown(
false);
395 ComboEdit->setShown(
false);
397 NameEdit->setFocus();
400 ButtAdd->setEnabled(
false);
401 ButtRem->setEnabled(
false);
403 Name->setText(item->text(0));
404 edit->setText(item->text(1));
406 NameEdit->setShown(
false);
407 NameEdit->setText(item->text(0));
408 Description->setShown(
true);
412 int b = PropDesc.find(
'[');
413 int e = PropDesc.findRev(
']');
415 QString str = PropDesc.mid(b+1, e-b-1);
416 str.replace( QRegExp(
"[^a-zA-Z0-9_,]"),
"" );
417 List = List.split(
',',str);
421 while(metrics.width(PropDesc) > 270) {
422 if (PropDesc.findRev(
' ') != -1)
423 PropDesc = PropDesc.left(PropDesc.findRev(
' ', -1)) +
"....";
425 PropDesc = PropDesc.left(PropDesc.length()-5) +
"....";
427 Description->setText(PropDesc);
429 if(List.count() >= 1) {
431 ComboEdit->insertStringList(List);
433 for(
int i=ComboEdit->count()-1;
i>=0;
i--)
434 if(item->text(1) == ComboEdit->text(
i)) {
435 ComboEdit->setCurrentItem(
i);
438 edit->setShown(
false);
439 ComboEdit->setShown(
true);
442 edit->setShown(
true);
443 ComboEdit->setShown(
false);
451 void ComponentDialog::slotApplyChange(
const QString&
Text)
454 prop->currentItem()->setText(1, Text);
456 ComboEdit->setFocus();
457 QListViewItem *item = prop->currentItem()->itemBelow();
458 if(item == 0)
return;
460 prop->setSelected(item,
true);
461 slotSelectProperty(item);
466 void ComponentDialog::slotApplyProperty()
468 QListViewItem *item = prop->currentItem();
471 if(ComboEdit->isShown())
472 edit->setText(ComboEdit->currentText());
474 if(item->text(1) != edit->text())
475 item->setText(1, edit->text());
477 if(NameEdit->isShown())
478 if(item->text(0) != NameEdit->text()) {
482 item->setText(0, NameEdit->text());
485 item = item->itemBelow();
491 prop->setSelected(item,
true);
492 prop->ensureItemVisible(item);
493 slotSelectProperty(item);
498 void ComponentDialog::slotApplyPropName()
500 QListViewItem *item = prop->currentItem();
501 if(item->text(0) != NameEdit->text()) {
507 item->setText(0, NameEdit->text());
514 void ComponentDialog::slotApplyState(
int State)
516 QListViewItem *item = prop->currentItem();
517 if(item == 0)
return;
520 if(State == QButton::On) ButtonState = tr(
"yes");
521 else ButtonState = tr(
"no");
523 if(item->text(2) != ButtonState) {
524 item->setText(2, ButtonState);
530 void ComponentDialog::slotButtOK()
538 void ComponentDialog::slotButtCancel()
553 void ComponentDialog::slotApplyInput()
555 if(Comp->
showName != showName->isChecked()) {
556 Comp->
showName = showName->isChecked();
562 if(CompNameEdit->text().isEmpty()) CompNameEdit->setText(Comp->
Name);
564 if(CompNameEdit->text() != Comp->
Name) {
566 if(pc->
Name == CompNameEdit->text())
568 if(pc) CompNameEdit->setText(Comp->
Name);
570 Comp->
Name = CompNameEdit->text();
579 display = checkSim->isChecked();
584 if(pp->
Value != editSim->currentText()) {
585 pp->
Value = editSim->currentText();
588 pp = Comp->
Props.next();
591 display = checkType->isChecked();
596 switch(comboType->currentItem()) {
597 case 1: tmp =
"log";
break;
598 case 2: tmp =
"list";
break;
599 case 3: tmp =
"const";
break;
600 default: tmp =
"lin";
break;
602 if(pp->
Value != tmp) {
606 pp = Comp->
Props.next();
608 if(checkParam)
if(checkParam->isEnabled()) {
609 display = checkParam->isChecked();
614 if(pp->
Value != editParam->text()) {
615 pp->
Value = editParam->text();
618 pp = Comp->
Props.next();
621 if(comboType->currentItem() < 2) {
622 display = checkStart->isChecked();
628 if(pp->
Value != editStart->text()) {
629 pp->
Value = editStart->text();
632 pp = Comp->
Props.next();
634 display = checkStop->isChecked();
640 if(pp->
Value != editStop->text()) {
641 pp->
Value = editStop->text();
644 pp = Comp->
Props.next();
646 display = checkNumber->isChecked();
651 if((pp->
Value != editNumber->text()) || (pp->
Name !=
"Points")) {
652 pp->
Value = editNumber->text();
656 pp = Comp->
Props.next();
663 pp = Comp->
Props.next();
666 pp = Comp->
Props.next();
668 display = checkValues->isChecked();
673 tmp =
"["+editValues->text()+
"]";
674 if((pp->
Value != tmp) || (pp->
Name !=
"Values")) {
679 pp = Comp->
Props.next();
684 QListViewItem *item = prop->firstChild();
687 item = prop->currentItem();
688 if(item->text(1) != edit->text())
689 item->setText(1, edit->text());
690 if(NameEdit->isShown())
691 if(item->text(0) != NameEdit->text())
692 item->setText(0, NameEdit->text());
696 for(item = prop->firstChild(); item != 0; item = item->itemBelow()) {
697 display = (item->text(2) == tr(
"yes"));
703 if(pp->
Value != item->text(1)) {
704 pp->
Value = item->text(1);
707 if(pp->
Name != item->text(0)) {
708 pp->
Name = item->text(0);
714 Comp->
Props.append(
new
715 Property(item->text(0), item->text(1), display, item->text(3)));
718 pp = Comp->
Props.next();
721 pp = Comp->
Props.prev();
723 while(pp != Comp->
Props.current())
724 Comp->
Props.remove();
733 Comp->
tx += tx_Dist-dx;
737 Comp->
ty += ty_Dist-dy;
742 Doc->viewport()->repaint();
747 void ComponentDialog::slotBrowseFile()
749 QString
s = QFileDialog::getOpenFileName(
QucsWorkDir.path(),
750 tr(
"All Files")+
" (*.*);;"+tr(
"Touchstone files")+
" (*.s?p);;"+
751 tr(
"CSV files")+
" (*.csv);;"+
752 tr(
"SPICE files")+
" (*.cir *.spi);;"+
753 tr(
"VHDL files")+
" (*.vhdl *.vhd);;"+
754 tr(
"Verilog files")+
" (*.v)",
755 this,
"", tr(
"Select a file"));
760 QucsWorkDir.absPath() == file.dirPath(
true)) s = file.fileName();
763 prop->currentItem()->setText(1, s);
767 void ComponentDialog::slotEditFile()
775 void ComponentDialog::slotButtAdd()
779 for(item = prop->firstChild(); item != 0; item = item->itemBelow())
780 if(item->text(0) == NameEdit->text()) {
781 prop->setSelected(item,
true);
782 slotSelectProperty(item);
786 item = prop->selectedItem();
787 if(item == 0) item = prop->lastItem();
789 QString s = tr(
"no");
790 if(disp->isChecked()) s = tr(
"yes");
792 prop->setSelected(
new QListViewItem(prop, item,
793 NameEdit->text(), edit->text(),
s),
true);
799 void ComponentDialog::slotButtRem()
801 if(prop->childCount() < 3)
return;
802 QListViewItem *item = prop->selectedItem();
803 if(item == 0)
return;
805 QListViewItem *next_item = item->itemBelow();
806 if(next_item == 0) next_item = item->itemAbove();
807 prop->takeItem(item);
810 slotSelectProperty(next_item);
814 void ComponentDialog::slotSimTypeChange(
int Type)
817 if(!editNumber->isEnabled()) {
820 editValues->text().section(
';', 0, 0).stripWhiteSpace());
822 editValues->text().section(
';', -1, -1).stripWhiteSpace());
823 editNumber->setText(
"2");
824 slotNumberChanged(0);
826 checkStart->setChecked(
true);
827 checkStop->setChecked(
true);
829 textValues->setDisabled(
true);
830 editValues->setDisabled(
true);
831 checkValues->setDisabled(
true);
832 textStart->setDisabled(
false);
833 editStart->setDisabled(
false);
834 checkStart->setDisabled(
false);
835 textStop->setDisabled(
false);
836 editStop->setDisabled(
false);
837 checkStop->setDisabled(
false);
838 textStep->setDisabled(
false);
839 editStep->setDisabled(
false);
840 textNumber->setDisabled(
false);
841 editNumber->setDisabled(
false);
842 checkNumber->setDisabled(
false);
844 textStep->setText(tr(
"Points per decade:"));
846 textStep->setText(tr(
"Step:"));
849 if(!editValues->isEnabled()) {
850 editValues->setText(editStart->text() +
"; " + editStop->text());
851 checkValues->setChecked(
true);
854 textValues->setDisabled(
false);
855 editValues->setDisabled(
false);
856 checkValues->setDisabled(
false);
857 textStart->setDisabled(
true);
858 editStart->setDisabled(
true);
859 checkStart->setDisabled(
true);
860 textStop->setDisabled(
true);
861 editStop->setDisabled(
true);
862 checkStop->setDisabled(
true);
863 textStep->setDisabled(
true);
864 editStep->setDisabled(
true);
865 textNumber->setDisabled(
true);
866 editNumber->setDisabled(
true);
867 checkNumber->setDisabled(
true);
868 textStep->setText(tr(
"Step:"));
874 void ComponentDialog::slotNumberChanged(
const QString&)
877 double x, y, Factor, ftmp;
878 if(comboType->currentItem() == 1) {
883 if(y == 0.0) y = x / 10.0;
884 if(x == 0.0) x = y * 10.0;
885 if(y == 0.0) { y = 1.0; x = 10.0; }
886 x = editNumber->text().toDouble() /
log10(fabs(x / y));
887 Unit = QString::number(x);
894 x = (x - y) / (editNumber->text().toDouble() - 1.0);
896 str2num(editStep->text(), y, tmp, ftmp);
902 Unit = QString::number(x/Factor) +
" " +
Unit;
905 editStep->blockSignals(
true);
906 editStep->setText(Unit);
907 editStep->blockSignals(
false);
911 void ComponentDialog::slotStepChanged(
const QString& Step)
915 if(comboType->currentItem() == 1) {
922 str2num(Step, y, Unit, Factor);
925 x =
log10(fabs(x)) * y;
934 str2num(Step, y, Unit, Factor);
940 editNumber->blockSignals(
true);
941 editNumber->setText(QString::number(
floor(x + 1.0)));
942 editNumber->blockSignals(
false);
947 void ComponentDialog::slotParamEntered()
949 if(editValues->isEnabled())
950 editValues->setFocus();
952 editStart->setFocus();
957 void ComponentDialog::slotSimEntered(
int)
959 editParam->setFocus();
964 void ComponentDialog::slotValuesEntered()
971 void ComponentDialog::slotStartEntered()
973 editStop->setFocus();
978 void ComponentDialog::slotStopEntered()
980 editStep->setFocus();
985 void ComponentDialog::slotStepEntered()
987 editNumber->setFocus();
992 void ComponentDialog::slotNumberEntered()