21 #include "components/component.h"
26 #include <qlineedit.h>
27 #include <qcombobox.h>
28 #include <qvalidator.h>
29 #include <qpushbutton.h>
30 #include <qscrollview.h>
32 #include <qcheckbox.h>
33 #include <qmessagebox.h>
37 : QDialog(Doc_, 0, TRUE, Qt::WDestructiveClose)
40 setCaption(tr(
"Change Component Properties"));
42 Expr.setPattern(
"[^\"=]+");
43 Validator =
new QRegExpValidator(Expr,
this);
44 Expr.setPattern(
"[\\w_]+");
45 ValRestrict =
new QRegExpValidator(Expr,
this);
49 all =
new QGridLayout(
this, 6,2,3,3);
52 all->addWidget(
new QLabel(tr(
"Components:"),
this), 0,0);
53 CompTypeEdit =
new QComboBox(
this);
54 CompTypeEdit->insertItem(tr(
"all components"));
55 CompTypeEdit->insertItem(tr(
"resistors"));
56 CompTypeEdit->insertItem(tr(
"capacitors"));
57 CompTypeEdit->insertItem(tr(
"inductors"));
58 CompTypeEdit->insertItem(tr(
"transistors"));
59 all->addWidget(CompTypeEdit, 0,1);
61 all->addWidget(
new QLabel(tr(
"Component Names:"),
this), 1,0);
62 CompNameEdit =
new QLineEdit(
this);
63 CompNameEdit->setValidator(Validator);
64 CompNameEdit->setText(
"*");
65 all->addWidget(CompNameEdit, 1,1);
68 all->addWidget(
new QLabel(tr(
"Property Name:"),
this), 2,0);
69 PropNameEdit =
new QComboBox(
this);
70 PropNameEdit->setEditable(
true);
71 PropNameEdit->setValidator(ValRestrict);
72 PropNameEdit->insertItem(
"Temp");
73 PropNameEdit->insertItem(
"Subst");
74 PropNameEdit->insertItem(
"Model");
75 all->addWidget(PropNameEdit, 2,1);
78 all->addWidget(
new QLabel(tr(
"New Value:"),
this), 3,0);
79 NewValueEdit =
new QLineEdit(
this);
80 NewValueEdit->setValidator(Validator);
81 NewValueEdit->setText(
"-273.15");
82 all->addWidget(NewValueEdit, 3,1);
86 QHBox *h0 =
new QHBox(
this);
88 all->setRowStretch(4,5);
89 all->addMultiCellWidget(h0, 5,5, 0,1);
90 connect(
new QPushButton(tr(
"Replace"),h0), SIGNAL(clicked()),
91 SLOT(slotButtReplace()));
92 connect(
new QPushButton(tr(
"Cancel"),h0), SIGNAL(clicked()),
106 bool ChangeDialog::matches(
const QString& CompModel)
108 switch(CompTypeEdit->currentItem()) {
110 case 1:
if(CompModel ==
"R")
return true;
112 case 2:
if(CompModel ==
"C")
return true;
114 case 3:
if(CompModel ==
"L")
return true;
116 case 4:
if(CompModel ==
"BJT")
return true;
117 if(CompModel ==
"_BJT")
return true;
118 if(CompModel ==
"JFET")
return true;
119 if(CompModel ==
"MOSFET")
return true;
120 if(CompModel ==
"_MOSFET")
return true;
129 void ChangeDialog::slotButtReplace()
131 Expr.setWildcard(
true);
132 Expr.setPattern(CompNameEdit->text());
141 QDialog *Dia =
new QDialog(
this);
142 Dia->setCaption(tr(
"Found Components"));
143 QVBoxLayout *Dia_All =
new QVBoxLayout(Dia);
144 Dia_All->setSpacing(3);
145 Dia_All->setMargin(5);
146 QScrollView *Dia_Scroll =
new QScrollView(Dia);
147 Dia_Scroll->setMargin(5);
148 Dia_All->addWidget(Dia_Scroll);
149 QVBox *Dia_Box =
new QVBox(Dia_Scroll->viewport());
150 Dia_Scroll->addChild(Dia_Box);
151 QLabel *Dia_Label =
new QLabel(tr(
"Change properties of\n")
152 + tr(
"these components ?"), Dia);
153 Dia_All->addWidget(Dia_Label);
155 QHBox *Dia_h =
new QHBox(Dia);
156 Dia_h->setSpacing(5);
157 Dia_All->addWidget(Dia_h);
158 QPushButton *YesButton =
new QPushButton(tr(
"Yes"), Dia_h);
159 connect(YesButton, SIGNAL(clicked()),
160 Dia, SLOT(accept()));
161 connect(
new QPushButton(tr(
"Cancel"), Dia_h), SIGNAL(clicked()),
162 Dia, SLOT(reject()));
165 QPtrList<QCheckBox> pList;
173 if(matches(pc->
Model)) {
174 if(Expr.search(pc->
Name) >= 0)
176 if(pp->Name == PropNameEdit->currentText()) {
177 pb =
new QCheckBox(pc->
Name, Dia_Box);
179 pb->setChecked(
true);
180 i1 = pp->Description.find(
'[');
183 i2 = pp->Description.findRev(
']');
185 str = pp->Description.mid(i1+1, i2-i1-1);
186 str.replace( QRegExp(
"[^a-zA-Z0-9_,]"),
"" );
187 List = List.split(
',',str);
188 if(List.findIndex(NewValueEdit->text()) >= 0)
191 pb->setChecked(
false);
192 pb->setEnabled(
false);
199 if(pList.isEmpty()) {
200 YesButton->setEnabled(
false);
202 (
new QLabel(tr(
"No match found!"), Dia_Box))->paletteBackgroundColor();
204 else theColor = pList.current()->paletteBackgroundColor();
206 Dia_Scroll->viewport()->setPaletteBackgroundColor(theColor);
207 Dia->resize(50, 300);
211 int Result = Dia->exec();
212 if(Result != QDialog::Accepted)
return;
215 bool changed =
false;
217 for(pb = pList.first(); pb!=0; pb = pList.next()) {
218 if(!pb->isChecked())
continue;
221 if(pb->text() != pc->
Name)
continue;
224 if(pp->Name != PropNameEdit->currentText())
continue;
226 int tx_Dist, ty_Dist, tmp;
228 tmp = pc->
tx+tx_Dist - pc->
x1;
229 if((tmp > 0) || (tmp < -6)) tx_Dist = 0;
230 tmp = pc->
ty+ty_Dist - pc->
y1;
231 if((tmp > 0) || (tmp < -6)) ty_Dist = 0;
233 pp->Value = NewValueEdit->text();
238 pc->
tx += tx_Dist-dx;
242 pc->
ty += ty_Dist-dy;
257 if(changed) accept();