21 #include <qlineedit.h>
22 #include <qtextedit.h>
23 #include <qvgroupbox.h>
24 #include <qcombobox.h>
25 #include <qfiledialog.h>
26 #include <qpushbutton.h>
27 #include <qmessagebox.h>
35 : QDialog(parent, 0, FALSE, Qt::WDestructiveClose)
37 setCaption(tr(
"Convert Data File..."));
39 all =
new QGridLayout(
this, 4, 3, 5, 3);
41 QVGroupBox *Group2 =
new QVGroupBox(tr(
"File specification"),
this);
42 all->addMultiCellWidget(Group2, 0,1, 0,2);
43 QWidget *f =
new QWidget(Group2);
44 QGridLayout *file =
new QGridLayout(f, 3, 3, 5);
45 file->addWidget(
new QLabel(tr(
"Input File:"), f), 0, 0);
48 QPushButton *BrowseButt =
new QPushButton(tr(
"Browse"), f);
49 file->addWidget(BrowseButt, 0, 2);
50 connect(BrowseButt, SIGNAL(clicked()), SLOT(slotBrowse()));
51 file->addWidget(
new QLabel(tr(
"Output File:"), f), 1, 0);
61 OutType->insertItem(tr(
"Qucs dataset"));
62 OutType->insertItem(tr(
"Touchstone"));
64 OutType->insertItem(tr(
"Qucs library"));
65 OutType->insertItem(tr(
"Qucs netlist"));
66 OutType->insertItem(tr(
"Matlab"));
67 connect(
OutType, SIGNAL(activated(
int)), SLOT(slotType(
int)));
70 QVGroupBox *Group1 =
new QVGroupBox(tr(
"Messages"),
this);
71 all->addMultiCellWidget(Group1, 2,2, 0,2);
73 MsgText =
new QTextEdit(Group1);
74 MsgText->setTextFormat(Qt::PlainText);
76 MsgText->setWordWrap(QTextEdit::NoWrap);
77 MsgText->setMinimumSize(250, 60);
79 QHBox *Butts =
new QHBox(
this);
80 all->addMultiCellWidget(Butts, 3,3, 0,2);
82 Butts->setStretchFactor(
new QWidget(Butts), 5);
84 ImportButt =
new QPushButton(tr(
"Convert"), Butts);
85 connect(
ImportButt, SIGNAL(clicked()), SLOT(slotImport()));
86 AbortButt =
new QPushButton(tr(
"Abort"), Butts);
88 connect(
AbortButt, SIGNAL(clicked()), SLOT(slotAbort()));
89 CancelButt =
new QPushButton(tr(
"Close"), Butts);
90 connect(
CancelButt, SIGNAL(clicked()), SLOT(reject()));
100 void ImportDialog::slotBrowse()
102 QString
s = QFileDialog::getOpenFileName(
105 " (*.s?p *.csv *.citi *.cit *.asc *.mdl *.vcd *.dat *.cir);;"+
106 tr(
"Touchstone files")+
" (*.s?p);;"+
107 tr(
"CSV files")+
" (*.csv);;"+
108 tr(
"CITI files")+
" (*.citi *.cit);;"+
109 tr(
"ZVR ASCII files")+
" (*.asc);;"+
110 tr(
"IC-CAP model files")+
" (*.mdl);;"+
111 tr(
"VCD files")+
" (*.vcd);;"+
112 tr(
"Qucs dataset files")+
" (*.dat);;"+
113 tr(
"SPICE files")+
" (*.cir);;"+
114 tr(
"Any file")+
" (*)",
115 this, 0, tr(
"Enter a Data File Name"));
123 switch(
OutType->currentItem()) {
151 void ImportDialog::slotImport()
162 if(QMessageBox::information(
this, tr(
"Info"),
163 tr(
"Output file already exists!")+
"\n"+tr(
"Overwrite it?"),
164 tr(
"&Yes"), tr(
"&No"), 0,1,1))
172 QString Suffix = Info.extension();
173 QStringList CommandLine;
176 if((Suffix ==
"citi") || (Suffix ==
"cit"))
177 CommandLine <<
"citi";
178 else if(Suffix ==
"vcd")
179 CommandLine <<
"vcd";
180 else if(Suffix ==
"asc")
181 CommandLine <<
"zvr";
182 else if(Suffix ==
"mdl")
183 CommandLine <<
"mdl";
184 else if(Suffix ==
"csv")
185 CommandLine <<
"csv";
186 else if(Suffix ==
"dat")
187 CommandLine <<
"qucsdata";
188 else if(Suffix ==
"cir")
189 CommandLine <<
"spice";
191 if(Suffix.at(0) ==
's')
192 if(Suffix.at(2) ==
'p')
193 if(Suffix.length() == 3)
194 if(Suffix.at(1).isDigit()) {
195 CommandLine <<
"touchstone";
199 MsgText->append(tr(
"ERROR: Unknown file format! Please check file name extension!"));
203 CommandLine <<
"-of";
204 switch(
OutType->currentItem()) {
206 CommandLine <<
"qucsdata";
209 CommandLine <<
"touchstone";
214 CommandLine <<
"csv";
219 CommandLine <<
"qucslib";
222 CommandLine <<
"qucs";
225 CommandLine <<
"matlab";
228 CommandLine <<
"qucsdata";
235 Process.setArguments(CommandLine);
239 connect(&
Process, SIGNAL(readyReadStderr()), SLOT(slotDisplayErr()));
240 connect(&
Process, SIGNAL(readyReadStdout()), SLOT(slotDisplayMsg()));
241 connect(&
Process, SIGNAL(processExited()), SLOT(slotProcessEnded()));
243 MsgText->append(tr(
"Running command line:")+
"\n");
244 MsgText->append(CommandLine.join(
" "));
248 MsgText->append(tr(
"ERROR: Cannot start converter!"));
252 void ImportDialog::slotType(
int index)
275 void ImportDialog::slotAbort()
284 void ImportDialog::slotDisplayMsg()
286 int par =
MsgText->paragraphs();
287 int idx =
MsgText->paragraphLength(par-1);
288 MsgText->setCursorPosition(par-1,idx);
294 void ImportDialog::slotDisplayErr()
296 int par =
MsgText->paragraphs();
297 int idx =
MsgText->paragraphLength(par-1);
298 MsgText->setCursorPosition(par-1,idx);
304 void ImportDialog::slotProcessEnded()
310 MsgText->append(tr(
"Successfully converted file!"));
312 disconnect(
CancelButt, SIGNAL(clicked()), 0, 0);
313 connect(
CancelButt, SIGNAL(clicked()), SLOT(accept()));
316 MsgText->append(tr(
"Converter ended with errors!"));