25 #include <qlistview.h>
26 #include <qcheckbox.h>
27 #include <qlineedit.h>
28 #include <qvgroupbox.h>
29 #include <qvalidator.h>
30 #include <qpushbutton.h>
31 #include <qmessagebox.h>
37 setCaption(tr(
"Edit Subcircuit Properties"));
39 v =
new QVBoxLayout(
this);
43 QHBox *h0 =
new QHBox(
this);
47 Expr.setPattern(
"[A-Za-z][A-Za-z0-9_]*");
48 SubVal =
new QRegExpValidator(Expr,
this);
49 new QLabel(tr(
"Prefix:"), h0);
50 Prefix =
new QLineEdit(h0);
51 Prefix->setValidator(SubVal);
52 Prefix->setText(idText->
Prefix);
55 QVGroupBox *ParamBox =
new QVGroupBox(tr(
"Parameters"),
this);
56 v->addWidget(ParamBox);
57 ParamList =
new QListView(ParamBox);
58 ParamList->addColumn(tr(
"display"));
59 ParamList->addColumn(tr(
"Name"));
60 ParamList->addColumn(tr(
"Default"));
61 ParamList->addColumn(tr(
"Description"));
62 ParamList->addColumn(tr(
"Type"));
63 ParamList->setSorting(-1);
67 new QListViewItem(ParamList,
68 pp->
display ? tr(
"yes") : tr(
"no"), pp->
Name.section(
'=', 0,0),
71 connect(ParamList, SIGNAL(selectionChanged(QListViewItem*)),
72 SLOT(slotEditParameter(QListViewItem*)));
74 showCheck =
new QCheckBox(tr(
"display in schematic"), ParamBox);
75 showCheck->setChecked(
true);
76 connect(showCheck, SIGNAL(toggled(
bool)), SLOT(slotToggleShow(
bool)));
78 QHBox *h1 =
new QHBox(ParamBox);
79 QVBox *v1 =
new QVBox(h1);
80 new QLabel(tr(
"Name:"), v1);
81 new QLabel(tr(
"Default Value:"), v1);
82 new QLabel(tr(
"Description:"), v1);
83 new QLabel(tr(
"Type:"), v1);
85 QVBox *v2 =
new QVBox(h1);
87 Expr.setPattern(
"[\\w_]+");
88 NameVal =
new QRegExpValidator(Expr,
this);
89 ParamNameEdit =
new QLineEdit(v2);
90 ParamNameEdit->setValidator(NameVal);
91 connect(ParamNameEdit, SIGNAL(textChanged(
const QString&)),
92 SLOT(slotNameChanged(
const QString&)));
94 Expr.setPattern(
"[^\"=]*");
95 ValueVal =
new QRegExpValidator(Expr,
this);
96 ValueEdit =
new QLineEdit(v2);
97 ValueEdit->setValidator(ValueVal);
98 connect(ValueEdit, SIGNAL(textChanged(
const QString&)),
99 SLOT(slotValueChanged(
const QString&)));
101 Expr.setPattern(
"[^\"=\\x005B\\x005D]*");
102 DescrVal =
new QRegExpValidator(Expr,
this);
103 DescriptionEdit =
new QLineEdit(v2);
104 DescriptionEdit->setValidator(DescrVal);
105 connect(DescriptionEdit, SIGNAL(textChanged(
const QString&)),
106 SLOT(slotDescrChanged(
const QString&)));
108 Expr.setPattern(
"[\\w_]+");
109 TypeVal =
new QRegExpValidator(Expr,
this);
110 TypeEdit =
new QLineEdit(v2);
111 TypeEdit->setValidator(TypeVal);
112 connect(TypeEdit, SIGNAL(textChanged(
const QString&)),
113 SLOT(slotTypeChanged(
const QString&)));
115 QHBox *h2 =
new QHBox(ParamBox);
116 h2->setStretchFactor(
new QWidget(h2), 10);
117 QPushButton *ButtAdd =
new QPushButton(tr(
"Add"), h2);
118 connect(ButtAdd, SIGNAL(clicked()), SLOT(slotAddParameter()));
119 QPushButton *ButtRemove =
new QPushButton(tr(
"Remove"), h2);
120 connect(ButtRemove, SIGNAL(clicked()), SLOT(slotRemoveParameter()));
122 QHBox *h3 =
new QHBox(
this);
126 QPushButton *ButtOK =
new QPushButton(tr(
"OK"),h3);
127 connect(ButtOK, SIGNAL(clicked()), SLOT(slotOk()));
128 QPushButton *ButtCancel =
new QPushButton(tr(
"Cancel"),h3);
129 connect(ButtCancel, SIGNAL(clicked()), SLOT(reject()));
145 void ID_Dialog::slotEditParameter(QListViewItem *Item)
148 ParamList->clearSelection();
149 ParamNameEdit->clear();
150 showCheck->setChecked(
true);
152 DescriptionEdit->clear();
157 showCheck->setChecked(Item->text(0) == tr(
"yes"));
158 ParamNameEdit->setText(Item->text(1));
159 ValueEdit->setText(Item->text(2));
160 DescriptionEdit->setText(Item->text(3));
161 TypeEdit->setText(Item->text(4));
165 void ID_Dialog::slotAddParameter()
167 if(ParamNameEdit->text().isEmpty())
170 if(ParamNameEdit->text() ==
"File") {
171 QMessageBox::critical(
this, tr(
"Error"),
172 tr(
"Parameter must not be named \"File\"!"));
176 QListViewItem *item, *lastItem=0;
177 for(item = ParamList->firstChild(); item!=0; item = item->itemBelow()) {
178 if(item->text(1) == ParamNameEdit->text()) {
179 QMessageBox::critical(
this, tr(
"Error"),
180 tr(
"Parameter \"%1\" already in list!").
arg(ParamNameEdit->text()));
187 new QListViewItem(ParamList, lastItem,
188 showCheck->isChecked() ? tr(
"yes") : tr(
"no"), ParamNameEdit->text(),
189 ValueEdit->text(), DescriptionEdit->text(), TypeEdit->text());
191 slotEditParameter(0);
192 ParamList->clearSelection();
196 void ID_Dialog::slotRemoveParameter()
198 QListViewItem *nextItem = 0;
200 QListViewItem *Item = ParamList->selectedItem();
202 nextItem = Item->itemBelow();
203 if(nextItem == 0) nextItem = Item->itemAbove();
204 ParamList->takeItem(Item);
208 slotEditParameter(nextItem);
212 void ID_Dialog::slotToggleShow(
bool On)
214 QListViewItem *Item = ParamList->selectedItem();
215 if(Item == 0)
return;
217 Item->setText(0, On ? tr(
"yes") : tr(
"no"));
221 void ID_Dialog::slotNameChanged(
const QString& text)
223 QListViewItem *Item = ParamList->selectedItem();
224 if(Item == 0)
return;
226 Item->setText(1, text);
230 void ID_Dialog::slotValueChanged(
const QString& text)
232 QListViewItem *Item = ParamList->selectedItem();
233 if(Item == 0)
return;
235 Item->setText(2, text);
239 void ID_Dialog::slotDescrChanged(
const QString& text)
241 QListViewItem *Item = ParamList->selectedItem();
242 if(Item == 0)
return;
244 Item->setText(3, text);
248 void ID_Dialog::slotTypeChanged(
const QString& text)
250 QListViewItem *Item = ParamList->selectedItem();
251 if(Item == 0)
return;
253 Item->setText(4, text);
257 void ID_Dialog::slotOk()
259 bool changed =
false;
261 if(!Prefix->text().isEmpty())
262 if(idText->
Prefix != Prefix->text()) {
263 idText->
Prefix = Prefix->text();
270 for(item = ParamList->firstChild(); item != 0; item = item->itemBelow()) {
271 s = item->text(1) +
"=" + item->text(2);
274 if(pp->
display != (item->text(0) == tr(
"yes"))) {
275 pp->
display = (item->text(0) == tr(
"yes"));
286 if(pp->
Type != item->text(4)) {
287 pp->
Type = item->text(4);
293 (item->text(0) == tr(
"yes")) ?
true :
false, s, item->text(3),
310 if(changed) accept();