Qucs-GUI  0.0.18
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
id_dialog.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  id_dialog.cpp
3  ---------------
4  begin : Sat Oct 16 2004
5  copyright : (C) 2004 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 #include <QtGui>
18 #include "id_dialog.h"
19 #include "id_text.h"
20 
21 #include <Q3HBox>
22 #include <Q3VBox>
23 #include <QLabel>
24 #include <QLayout>
25 #include <Q3ListView>
26 #include <QCheckBox>
27 #include <QLineEdit>
28 #include <Q3VGroupBox>
29 #include <QValidator>
30 #include <QPushButton>
31 #include <QMessageBox>
32 //Added by qt3to4:
33 #include <Q3VBoxLayout>
34 
35 
37 {
38  idText = idText_;
39  setCaption(tr("Edit Subcircuit Properties"));
40 
41  v = new Q3VBoxLayout(this);
42  v->setSpacing(5);
43  v->setMargin(5);
44 
45  Q3HBox *h0 = new Q3HBox(this);
46  h0->setSpacing(5);
47  v->addWidget(h0);
48 
49  Expr.setPattern("[A-Za-z][A-Za-z0-9_]*");
50  SubVal = new QRegExpValidator(Expr, this);
51  new QLabel(tr("Prefix:"), h0);
52  Prefix = new QLineEdit(h0);
53  Prefix->setValidator(SubVal);
54  Prefix->setText(idText->Prefix);
55 
56 
57  Q3VGroupBox *ParamBox = new Q3VGroupBox(tr("Parameters"), this);
58  v->addWidget(ParamBox);
59  ParamList = new Q3ListView(ParamBox);
60  ParamList->addColumn(tr("display"));
61  ParamList->addColumn(tr("Name"));
62  ParamList->addColumn(tr("Default"));
63  ParamList->addColumn(tr("Description"));
64  ParamList->addColumn(tr("Type"));
65  ParamList->setSorting(-1); // no sorting
66 
67  SubParameter *pp;
68  for(pp = idText->Parameter.last(); pp!=0; pp = idText->Parameter.prev())
69  new Q3ListViewItem(ParamList,
70  pp->display ? tr("yes") : tr("no"), pp->Name.section('=', 0,0),
71  pp->Name.section('=', 1,1), pp->Description, pp->Type);
72 
73  connect(ParamList, SIGNAL(selectionChanged(Q3ListViewItem*)),
74  SLOT(slotEditParameter(Q3ListViewItem*)));
75 
76  showCheck = new QCheckBox(tr("display in schematic"), ParamBox);
77  showCheck->setChecked(true);
78  connect(showCheck, SIGNAL(toggled(bool)), SLOT(slotToggleShow(bool)));
79 
80  Q3HBox *h1 = new Q3HBox(ParamBox);
81  Q3VBox *v1 = new Q3VBox(h1);
82  new QLabel(tr("Name:"), v1);
83  new QLabel(tr("Default Value:"), v1);
84  new QLabel(tr("Description:"), v1);
85  new QLabel(tr("Type:"), v1);
86 
87  Q3VBox *v2 = new Q3VBox(h1);
88 
89  Expr.setPattern("[\\w_]+");
90  NameVal = new QRegExpValidator(Expr, this);
91  ParamNameEdit = new QLineEdit(v2);
92  ParamNameEdit->setValidator(NameVal);
93  connect(ParamNameEdit, SIGNAL(textChanged(const QString&)),
94  SLOT(slotNameChanged(const QString&)));
95 
96  Expr.setPattern("[^\"=]*");
97  ValueVal = new QRegExpValidator(Expr, this);
98  ValueEdit = new QLineEdit(v2);
99  ValueEdit->setValidator(ValueVal);
100  connect(ValueEdit, SIGNAL(textChanged(const QString&)),
101  SLOT(slotValueChanged(const QString&)));
102 
103  Expr.setPattern("[^\"=\\x005B\\x005D]*");
104  DescrVal = new QRegExpValidator(Expr, this);
105  DescriptionEdit = new QLineEdit(v2);
106  DescriptionEdit->setValidator(DescrVal);
107  connect(DescriptionEdit, SIGNAL(textChanged(const QString&)),
108  SLOT(slotDescrChanged(const QString&)));
109 
110  Expr.setPattern("[\\w_]+");
111  TypeVal = new QRegExpValidator(Expr, this);
112  TypeEdit = new QLineEdit(v2);
113  TypeEdit->setValidator(TypeVal);
114  connect(TypeEdit, SIGNAL(textChanged(const QString&)),
115  SLOT(slotTypeChanged(const QString&)));
116 
117  Q3HBox *h2 = new Q3HBox(ParamBox);
118  h2->setStretchFactor(new QWidget(h2), 10);
119  QPushButton *ButtAdd = new QPushButton(tr("Add"), h2);
120  connect(ButtAdd, SIGNAL(clicked()), SLOT(slotAddParameter()));
121  QPushButton *ButtRemove = new QPushButton(tr("Remove"), h2);
122  connect(ButtRemove, SIGNAL(clicked()), SLOT(slotRemoveParameter()));
123 
124  Q3HBox *h3 = new Q3HBox(this);
125  h3->setSpacing(5);
126  v->addWidget(h3);
127 
128  QPushButton *ButtOK = new QPushButton(tr("OK"),h3);
129  connect(ButtOK, SIGNAL(clicked()), SLOT(slotOk()));
130  QPushButton *ButtCancel = new QPushButton(tr("Cancel"),h3);
131  connect(ButtCancel, SIGNAL(clicked()), SLOT(reject()));
132 
133  resize(320, 350);
134 }
135 
137 {
138  delete v;
139  delete SubVal;
140  delete NameVal;
141  delete ValueVal;
142  delete DescrVal;
143  delete TypeVal;
144 }
145 
146 // -----------------------------------------------------------
147 void ID_Dialog::slotEditParameter(Q3ListViewItem *Item)
148 {
149  if(Item == 0) {
150  ParamList->clearSelection();
151  ParamNameEdit->clear();
152  showCheck->setChecked(true);
153  ValueEdit->clear();
154  DescriptionEdit->clear();
155  TypeEdit->clear();
156  return;
157  }
158 
159  showCheck->setChecked(Item->text(0) == tr("yes"));
160  ParamNameEdit->setText(Item->text(1));
161  ValueEdit->setText(Item->text(2));
162  DescriptionEdit->setText(Item->text(3));
163  TypeEdit->setText(Item->text(4));
164 }
165 
166 // -----------------------------------------------------------
168 {
169  if(ParamNameEdit->text().isEmpty())
170  return;
171 
172  if(ParamNameEdit->text() == "File") {
173  QMessageBox::critical(this, tr("Error"),
174  tr("Parameter must not be named \"File\"!"));
175  return;
176  }
177 
178  Q3ListViewItem *item, *lastItem=0;
179  for(item = ParamList->firstChild(); item!=0; item = item->itemBelow()) {
180  if(item->text(1) == ParamNameEdit->text()) {
181  QMessageBox::critical(this, tr("Error"),
182  tr("Parameter \"%1\" already in list!").arg(ParamNameEdit->text()));
183  return;
184  }
185  lastItem = item;
186  }
187 
188 
189  new Q3ListViewItem(ParamList, lastItem,
190  showCheck->isChecked() ? tr("yes") : tr("no"), ParamNameEdit->text(),
191  ValueEdit->text(), DescriptionEdit->text(), TypeEdit->text());
192 
193  slotEditParameter(0); // clear entry fields
194  ParamList->clearSelection();
195 }
196 
197 // -----------------------------------------------------------
199 {
200  Q3ListViewItem *nextItem = 0;
201 
202  Q3ListViewItem *Item = ParamList->selectedItem();
203  if(Item) {
204  nextItem = Item->itemBelow();
205  if(nextItem == 0) nextItem = Item->itemAbove();
206  ParamList->takeItem(Item); // remove from ListView
207  delete Item; // delete item
208  }
209 
210  slotEditParameter(nextItem);
211 }
212 
213 // -----------------------------------------------------------
215 {
216  Q3ListViewItem *Item = ParamList->selectedItem();
217  if(Item == 0) return;
218 
219  Item->setText(0, On ? tr("yes") : tr("no"));
220 }
221 
222 // -----------------------------------------------------------
223 void ID_Dialog::slotNameChanged(const QString& text)
224 {
225  Q3ListViewItem *Item = ParamList->selectedItem();
226  if(Item == 0) return;
227 
228  Item->setText(1, text);
229 }
230 
231 // -----------------------------------------------------------
232 void ID_Dialog::slotValueChanged(const QString& text)
233 {
234  Q3ListViewItem *Item = ParamList->selectedItem();
235  if(Item == 0) return;
236 
237  Item->setText(2, text);
238 }
239 
240 // -----------------------------------------------------------
241 void ID_Dialog::slotDescrChanged(const QString& text)
242 {
243  Q3ListViewItem *Item = ParamList->selectedItem();
244  if(Item == 0) return;
245 
246  Item->setText(3, text);
247 }
248 
249 // -----------------------------------------------------------
250 void ID_Dialog::slotTypeChanged(const QString& text)
251 {
252  Q3ListViewItem *Item = ParamList->selectedItem();
253  if(Item == 0) return;
254 
255  Item->setText(4, text);
256 }
257 
258 // -----------------------------------------------------------
260 {
261  bool changed = false;
262 
263  if(!Prefix->text().isEmpty())
264  if(idText->Prefix != Prefix->text()) {
265  idText->Prefix = Prefix->text();
266  changed = true;
267  }
268 
269  QString s;
270  Q3ListViewItem *item;
271  SubParameter *pp = idText->Parameter.first();
272  for(item = ParamList->firstChild(); item != 0; item = item->itemBelow()) {
273  s = item->text(1) + "=" + item->text(2);
274 
275  if(pp) {
276  if(pp->display != (item->text(0) == tr("yes"))) {
277  pp->display = (item->text(0) == tr("yes"));
278  changed = true;
279  }
280  if(pp->Name != s) {
281  pp->Name = s;
282  changed = true;
283  }
284  if(pp->Description != item->text(3)) {
285  pp->Description = item->text(3);
286  changed = true;
287  }
288  if(pp->Type != item->text(4)) {
289  pp->Type = item->text(4);
290  changed = true;
291  }
292  }
293  else {
294  idText->Parameter.append(new SubParameter(
295  (item->text(0) == tr("yes")) ? true : false, s, item->text(3),
296  item->text(4)));
297  changed = true;
298  }
299 
300  pp = idText->Parameter.next();
301  }
302 
303  // if more properties than in ListView -> delete the rest
304  if(pp) {
305  pp = idText->Parameter.prev();
306  idText->Parameter.last();
307  while(pp != idText->Parameter.current())
308  idText->Parameter.remove();
309  changed = true;
310  }
311 
312  if(changed) accept();
313  else reject();
314 }
QString Prefix
Definition: id_text.h:59
QRegExpValidator * TypeVal
Definition: id_dialog.h:53
QRegExpValidator * NameVal
Definition: id_dialog.h:53
Q3ListView * ParamList
Definition: id_dialog.h:48
QRegExp Expr
Definition: id_dialog.h:52
QString Description
Definition: id_text.h:34
void slotEditParameter(Q3ListViewItem *)
Definition: id_dialog.cpp:147
ID_Dialog(ID_Text *)
Definition: id_dialog.cpp:36
QLineEdit * DescriptionEdit
Definition: id_dialog.h:50
Q3VBoxLayout * v
Definition: id_dialog.h:45
void slotRemoveParameter()
Definition: id_dialog.cpp:198
ID_Text * idText
Definition: id_dialog.h:43
QRegExpValidator * ValueVal
Definition: id_dialog.h:53
void slotNameChanged(const QString &)
Definition: id_dialog.cpp:223
void slotDescrChanged(const QString &)
Definition: id_dialog.cpp:241
QRegExpValidator * SubVal
Definition: id_dialog.h:53
QLineEdit * ValueEdit
Definition: id_dialog.h:50
void slotValueChanged(const QString &)
Definition: id_dialog.cpp:232
QLineEdit * ParamNameEdit
Definition: id_dialog.h:50
QLineEdit * Prefix
Definition: id_dialog.h:46
QString Type
Definition: id_text.h:34
QString Name
Definition: id_text.h:34
void slotAddParameter()
Definition: id_dialog.cpp:167
bool display
Definition: id_text.h:31
void slotTypeChanged(const QString &)
Definition: id_dialog.cpp:250
void slotOk()
Definition: id_dialog.cpp:259
Q3PtrList< SubParameter > Parameter
Definition: id_text.h:60
QCheckBox * showCheck
Definition: id_dialog.h:49
QLineEdit * TypeEdit
Definition: id_dialog.h:50
QRegExpValidator * DescrVal
Definition: id_dialog.h:53
void slotToggleShow(bool)
Definition: id_dialog.cpp:214