Skip to content

Commit 7fd7b39

Browse files
author
ela
committed
2009-05-03 Stefan Jahn <[email protected]>
* qf_settings.cpp (saveXmlSettings): Added XML saving / loading capabilities.
1 parent b7fa0d4 commit 7fd7b39

File tree

7 files changed

+253
-20
lines changed

7 files changed

+253
-20
lines changed

qucs-filter-v2/ChangeLog

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2009-05-03 Stefan Jahn <[email protected]>
2+
3+
* qf_settings.cpp (saveXmlSettings): Added XML saving / loading
4+
capabilities.
5+
6+
2009-05-01 Stefan Jahn <[email protected]>
7+
8+
* ChangeLog: Created this file.

qucs-filter-v2/qf_box.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,15 @@ class qf_box : public FilterDialog {
2323
void updateDialog (void);
2424
void populateOrderCombo (void);
2525

26+
public slots:
27+
28+
void on_FilterName_activated (int);
29+
void on_TformName_activated (int);
30+
2631
private slots:
2732

2833
bool semanticCheck (void);
2934

30-
void on_FilterName_activated (int);
31-
void on_TformName_activated (int);
3235
void on_OrderBox_stateChanged (int);
3336
void on_OrderCombo_activated (int);
3437
void on_SubOrderCombo_activated (int);

qucs-filter-v2/qf_comp.cpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ static QString valstr (qf_double_t num) {
2929

3030
num = fabs (num);
3131

32-
if ((num > 1e-18) && (num < 1e6)) {
32+
if ((num > 1e-18) && (num < 1e12)) {
3333
qf_double_t cal = floor (log10 (num) / 3);
3434
int expo = static_cast <int> (cal);
3535

@@ -42,6 +42,9 @@ static QString valstr (qf_double_t num) {
4242
case -1: c = 'm'; break;
4343
case 0: break;
4444
case 1: c = 'k'; break;
45+
case 2: c = 'M'; break;
46+
case 3: c = 'G'; break;
47+
case 4: c = 'T'; break;
4548
}
4649

4750
if (c != 0) num /= pow (10.0, 3 * cal);
@@ -321,7 +324,7 @@ void qf_lcmp::dump_all (QTextStream& out) {
321324

322325
// S-parameter simulation box and equation
323326
com << "<.SP SP1 1 " << x << " " << y-280 << " 0 50 0 0 \"log\" 1 \""
324-
<< valstr(fc/50) << "Hz\" 1 \"" << valstr(fc*50)
327+
<< valstr(fc/2/M_PI/10) << "Hz\" 1 \"" << valstr(fc/2/M_PI*10)
325328
<< "Hz\" 1 \"200\" 1 \"no\" 0 \"1\" 0 \"2\" 0>\n";
326329
com << "<Eqn Eqn1 1 " << x+200 << " " << y-270
327330
<< " -28 15 0 0 \"dBS21=dB(S[2,1])\" 1 "
@@ -339,7 +342,7 @@ void qf_lcmp::dump_all (QTextStream& out) {
339342
out << "<Paintings>\n";
340343
out << "<Text " << x+310 << " " << y-280 << " 12 #000000 0 \""
341344
<< tx << "\\n"
342-
<< valstr(fc) << "Hz cutoff/center frequency\\n"
345+
<< valstr(fc/2/M_PI) << "Hz cutoff/center frequency\\n"
343346
<< "impedance matching Z_{IN}=" << valstr(r1) << "\\Omega, Z_{OUT}="
344347
<< valstr(r2) << "\\Omega\">\n";
345348
out << "</Paintings>\n";

qucs-filter-v2/qf_main.cpp

+29-5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
#include <qdir.h>
1111
#include <qtextcodec.h>
1212
#include <qclipboard.h>
13+
#include <qlineedit.h>
14+
#include <qcombobox.h>
15+
#include <qcheckbox.h>
1316

1417
#include "qf_common.h"
1518
#include "qf_poly.h"
@@ -63,10 +66,30 @@ int main (int argc, char * argv []) {
6366
tor.load( QString("qucs_") + lang, QucsSettings.LangDir);
6467
app.installTranslator( &tor );
6568

66-
qf_box Filterbox;
67-
Filterbox. setFont (QucsSettings.font);
68-
Filterbox. move (QucsSettings.x, QucsSettings.y);
69-
Filterbox. show ();
69+
qf_box Filterbox;
70+
Filterbox.setFont (QucsSettings.font);
71+
Filterbox.move (QucsSettings.x, QucsSettings.y);
72+
Filterbox.show ();
73+
74+
Filterbox.FilterName->setCurrentItem (QucsSettings.type);
75+
Filterbox.on_FilterName_activated (QucsSettings.form);
76+
Filterbox.TformName->setCurrentItem (QucsSettings.form);
77+
Filterbox.on_TformName_activated (QucsSettings.type);
78+
79+
Filterbox.EnterCutoff->setText (QString::number (QucsSettings.cutoff));
80+
Filterbox.CutoffCombo->setCurrentItem (QucsSettings.cutoff_unit);
81+
Filterbox.EnterZin->setText (QString::number (QucsSettings.zin));
82+
Filterbox.EnterZout->setText (QString::number (QucsSettings.zout));
83+
Filterbox.OrderBox->setChecked (QucsSettings.specify);
84+
Filterbox.OrderCombo->setCurrentItem (QucsSettings.ord);
85+
Filterbox.SubOrderCombo->setCurrentItem (QucsSettings.subord);
86+
Filterbox.EnterBandwidth->setText (QString::number (QucsSettings.bw));
87+
Filterbox.BandwidthCombo->setCurrentItem (QucsSettings.bw_unit);
88+
Filterbox.EnterStopband->setText (QString::number (QucsSettings.sb));
89+
Filterbox.StopbandCombo->setCurrentItem (QucsSettings.sb_unit);
90+
Filterbox.EnterRipple->setText (QString::number (QucsSettings.ripple));
91+
Filterbox.EnterAngle->setText (QString::number (QucsSettings.angle));
92+
Filterbox.EnterAttenuation->setText (QString::number (QucsSettings.atten));
7093

7194
while (true) {
7295
if (Filterbox. exec () != QDialog::Accepted) break;
@@ -84,6 +107,7 @@ int main (int argc, char * argv []) {
84107

85108
}
86109

87-
saveApplSettings (&Filterbox);
110+
saveSettings (&Filterbox);
111+
saveXmlSettings (&Filterbox);
88112
return result;
89113
}

qucs-filter-v2/qf_settings.cpp

+179-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
#include <qfile.h>
1515
#include <qdir.h>
1616
#include <qmessagebox.h>
17+
#include <qcheckbox.h>
18+
#include <qcombobox.h>
19+
#include <qlineedit.h>
20+
#include <qdom.h>
1721

1822
#include "qf_box.h"
1923
#include "qf_settings.h"
@@ -22,7 +26,7 @@ struct tQucsSettings QucsSettings;
2226

2327
// #########################################################################
2428
// Loads the settings file and stores the settings.
25-
bool loadSettings()
29+
bool loadSettings (void)
2630
{
2731
bool result = true;
2832

@@ -34,6 +38,11 @@ bool loadSettings()
3438
QString Line, Setting;
3539
while(!stream.atEnd()) {
3640
Line = stream.readLine();
41+
if (Line.left(9) == "<!DOCTYPE") {
42+
file.close ();
43+
result = loadXmlSettings ();
44+
break;
45+
}
3746
Setting = Line.section('=',0,0);
3847
Line = Line.section('=',1,1);
3948
if(Setting == "FilterWindow") {
@@ -43,7 +52,7 @@ bool loadSettings()
4352
}
4453
}
4554
file.close();
46-
}
55+
}
4756

4857
file.setName(QDir::homeDirPath()+QDir::convertSeparators ("/.qucs/qucsrc"));
4958
if(!file.open(IO_ReadOnly))
@@ -67,7 +76,7 @@ bool loadSettings()
6776

6877
// #########################################################################
6978
// Saves the settings in the settings file.
70-
bool saveApplSettings(qf_box *qucs)
79+
bool saveSettings(qf_box *qucs)
7180
{
7281
if(qucs->x() == QucsSettings.x)
7382
if(qucs->y() == QucsSettings.y)
@@ -90,3 +99,170 @@ bool saveApplSettings(qf_box *qucs)
9099
file.close();
91100
return true;
92101
}
102+
103+
// #########################################################################
104+
// Saves the application settings in the XML settings file.
105+
bool saveXmlSettings (qf_box * qucs)
106+
{
107+
QDomDocument doc ("QucsFilter");
108+
QDomElement el, gr, rt;
109+
110+
rt = doc.createElement ("Settings");
111+
doc.appendChild (rt);
112+
113+
el = doc.createElement ("Version");
114+
el.setAttribute ("value", PACKAGE_VERSION);
115+
rt.appendChild (el);
116+
117+
el = doc.createElement ("Window");
118+
el.setAttribute ("x", qucs->x());
119+
el.setAttribute ("y", qucs->y());
120+
rt.appendChild (el);
121+
122+
gr = doc.createElement ("LC");
123+
el = doc.createElement ("Type");
124+
el.setAttribute ("Type", qucs->FilterName->currentItem ());
125+
el.setAttribute ("Class", qucs->TformName->currentItem ());
126+
el.setAttribute ("SpecifyOrder", qucs->OrderBox->isChecked ());
127+
el.setAttribute ("Order", qucs->OrderCombo->currentItem ());
128+
el.setAttribute ("SubOrder", qucs->SubOrderCombo->currentItem ());
129+
gr.appendChild (el);
130+
el = doc.createElement ("Cutoff");
131+
el.setAttribute ("Value", qucs->EnterCutoff->text ());
132+
el.setAttribute ("Unit", qucs->CutoffCombo->currentItem ());
133+
gr.appendChild (el);
134+
el = doc.createElement ("Bandwidth");
135+
el.setAttribute ("Value", qucs->EnterBandwidth->text ());
136+
el.setAttribute ("Unit", qucs->BandwidthCombo->currentItem ());
137+
gr.appendChild (el);
138+
el = doc.createElement ("Stopband");
139+
el.setAttribute ("Value", qucs->EnterStopband->text ());
140+
el.setAttribute ("Unit", qucs->StopbandCombo->currentItem ());
141+
gr.appendChild (el);
142+
el = doc.createElement ("Ripple");
143+
el.setAttribute ("Value", qucs->EnterRipple->text ());
144+
gr.appendChild (el);
145+
el = doc.createElement ("Angle");
146+
el.setAttribute ("Value", qucs->EnterAngle->text ());
147+
gr.appendChild (el);
148+
el = doc.createElement ("Attenuation");
149+
el.setAttribute ("Value", qucs->EnterAttenuation->text ());
150+
gr.appendChild (el);
151+
el = doc.createElement ("Impedance");
152+
el.setAttribute ("Zin", qucs->EnterZin->text ());
153+
el.setAttribute ("Zout", qucs->EnterZout->text ());
154+
gr.appendChild (el);
155+
rt.appendChild (gr);
156+
157+
QFile file (QDir::homeDirPath()+QDir::convertSeparators ("/.qucs/filterrc"));
158+
if (!file.open (IO_WriteOnly)) {
159+
QMessageBox::warning (0,
160+
QObject::tr("Warning"),
161+
QObject::tr("Cannot save settings file !"));
162+
return false;
163+
}
164+
165+
QTextStream str (&file);
166+
str << doc.toString ();
167+
file.close ();
168+
return true;
169+
}
170+
171+
// #########################################################################
172+
// Helper function to find XML nodes and attributes
173+
static QString getXml (QDomDocument * doc, const QString type,
174+
const QString attr, const QString group = "")
175+
{
176+
QDomElement docElem = doc->documentElement ();
177+
178+
QDomNode n = docElem.firstChild ();
179+
while (!n.isNull()) {
180+
QDomElement e = n.toElement ();
181+
if (!e.isNull()) {
182+
if (group.isEmpty ()) {
183+
if (e.tagName () == type) {
184+
return e.attribute (attr, "");
185+
}
186+
}
187+
else {
188+
if (e.tagName () == group) {
189+
QDomNode ng = e.firstChild ();
190+
while (!ng.isNull()) {
191+
QDomElement eg = ng.toElement ();
192+
if (!eg.isNull()) {
193+
if (eg.tagName () == type) {
194+
return eg.attribute (attr, "");
195+
}
196+
}
197+
ng = ng.nextSibling();
198+
}
199+
}
200+
}
201+
}
202+
n = n.nextSibling();
203+
}
204+
return "";
205+
}
206+
207+
static int getInteger (QDomDocument * doc, const QString type,
208+
const QString attr, const QString group = "")
209+
{
210+
return getXml (doc, type, attr, group).toInt ();
211+
}
212+
213+
static double getDouble (QDomDocument * doc, const QString type,
214+
const QString attr, const QString group = "")
215+
{
216+
return getXml (doc, type, attr, group).toDouble ();
217+
}
218+
219+
static QString getString (QDomDocument * doc, const QString type,
220+
const QString attr, const QString group = "")
221+
{
222+
return getXml (doc, type, attr, group);
223+
}
224+
225+
// #########################################################################
226+
// Loads the XML settings file and stores the settings.
227+
bool loadXmlSettings (void)
228+
{
229+
bool result = true;
230+
231+
QFile file (QDir::homeDirPath()+QDir::convertSeparators ("/.qucs/filterrc"));
232+
if (!file.open(IO_ReadOnly))
233+
result = false; // settings file doesn't exist
234+
else {
235+
QDomDocument doc;
236+
QString errmsg;
237+
int line, col;
238+
if (!doc.setContent(&file, true, &errmsg, &line, &col)) {
239+
cerr << file.name () << ":" << line << ":" << col
240+
<< ": " << errmsg << endl;
241+
cerr << doc.toCString ();
242+
file.close();
243+
return false;
244+
}
245+
246+
QucsSettings.x = getInteger (&doc, "Window", "x");
247+
QucsSettings.y = getInteger (&doc, "Window", "y");
248+
249+
QucsSettings.type = getInteger (&doc, "Type", "Type", "LC");
250+
QucsSettings.form = getInteger (&doc, "Type", "Class", "LC");
251+
QucsSettings.specify = getInteger (&doc, "Type", "SpecifyOrder", "LC");
252+
QucsSettings.ord = getInteger (&doc, "Type", "Order", "LC");
253+
QucsSettings.subord = getInteger (&doc, "Type", "SubOrder", "LC");
254+
255+
QucsSettings.cutoff = getDouble (&doc, "Cutoff", "Value", "LC");
256+
QucsSettings.cutoff_unit = getInteger (&doc, "Cutoff", "Unit", "LC");
257+
QucsSettings.zin = getDouble (&doc, "Impedance", "Zin", "LC");
258+
QucsSettings.zout = getDouble (&doc, "Impedance", "Zout", "LC");
259+
QucsSettings.bw = getDouble (&doc, "Bandwidth", "Value", "LC");
260+
QucsSettings.bw_unit = getInteger (&doc, "Bandwidth", "Unit", "LC");
261+
QucsSettings.sb = getDouble (&doc, "Stopband", "Value", "LC");
262+
QucsSettings.sb_unit = getInteger (&doc, "Stopband", "Unit", "LC");
263+
QucsSettings.ripple = getDouble (&doc, "Ripple", "Value", "LC");
264+
QucsSettings.angle = getDouble (&doc, "Angle", "Value", "LC");
265+
QucsSettings.atten = getDouble (&doc, "Attenuation", "Value", "LC");
266+
}
267+
return result;
268+
}

qucs-filter-v2/qf_settings.h

+20-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,22 @@
88
***************************************************************************/
99

1010
struct tQucsSettings {
11-
int x, y; // position of main window
11+
int x, y; // position of main window
12+
double cutoff; // cutoff frequency
13+
int cutoff_unit; // cutoff frequency unit
14+
double zin, zout; // in/output impedances
15+
int type;
16+
int form;
17+
int ord;
18+
int specify;
19+
int subord;
20+
double bw;
21+
int bw_unit;
22+
double sb;
23+
int sb_unit;
24+
double ripple;
25+
double angle;
26+
double atten;
1227
QFont font;
1328
QString LangDir;
1429
QString BitmapDir;
@@ -17,6 +32,8 @@ struct tQucsSettings {
1732

1833
extern struct tQucsSettings QucsSettings;
1934

20-
bool loadSettings();
21-
bool saveApplSettings(qf_box *);
35+
bool loadSettings (void);
36+
bool saveSettings (qf_box *);
37+
bool loadXmlSettings (void);
38+
bool saveXmlSettings (qf_box *);
2239

qucs-filter-v2/qf_zigzag.cpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -344,8 +344,10 @@ void qf_zigzag::synth_zz (qf_cauer* F) {
344344

345345
void qf_zigzag::dump (QTextStream& out) {
346346

347-
out << "Zigzag filter of order " << Tspec -> ord << endl;
348-
out << "Zin " << Tspec -> r1 << endl;
349-
lcmp. dump_all (out);
350-
out << "Zout " << Tspec -> r2 << endl;
347+
lcmp.tx = qf_filter_apis [Tspec -> filter] -> name + " zigzag filter" +
348+
" of order " + QString::number(Tspec -> ord);
349+
lcmp.r1 = Tspec -> r1;
350+
lcmp.r2 = Tspec -> r2;
351+
lcmp.fc = Tspec -> fc;
352+
lcmp.dump_all (out);
351353
}

0 commit comments

Comments
 (0)