summaryrefslogtreecommitdiff
authorcniehaus <cniehaus>2002-09-15 16:18:47 (UTC)
committer cniehaus <cniehaus>2002-09-15 16:18:47 (UTC)
commit7a8dc6b0a16db160a1e50fde8f298eb9e3cb0099 (patch) (unidiff)
tree16e49af9eabdcf6621654a1f80488c65951fe4b5
parenta013fbe2ba39e5ebd249766f223dbb67fe18027c (diff)
downloadopie-7a8dc6b0a16db160a1e50fde8f298eb9e3cb0099.zip
opie-7a8dc6b0a16db160a1e50fde8f298eb9e3cb0099.tar.gz
opie-7a8dc6b0a16db160a1e50fde8f298eb9e3cb0099.tar.bz2
wow... I just don't get my own code... Help needed
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/checkbook/calcdlg.ui44
-rw-r--r--noncore/apps/checkbook/calcdlgui.cpp69
-rw-r--r--noncore/apps/checkbook/calcdlgui.h29
-rw-r--r--noncore/apps/checkbook/kmolcalc.cpp4
-rw-r--r--noncore/apps/checkbook/oxygen.cpp5
-rw-r--r--noncore/apps/checkbook/oxygen.pro4
6 files changed, 84 insertions, 71 deletions
diff --git a/noncore/apps/checkbook/calcdlg.ui b/noncore/apps/checkbook/calcdlg.ui
index 7637ca8..e0b19f9 100644
--- a/noncore/apps/checkbook/calcdlg.ui
+++ b/noncore/apps/checkbook/calcdlg.ui
@@ -1,243 +1,243 @@
1<!DOCTYPE UI><UI> 1<!DOCTYPE UI><UI>
2<class>CalcDlg</class> 2<class>CalcDlg</class>
3<widget> 3<widget>
4 <class>QWidget</class> 4 <class>QWidget</class>
5 <property stdset="1"> 5 <property stdset="1">
6 <name>name</name> 6 <name>name</name>
7 <cstring>CalcDlg</cstring> 7 <cstring>CalcDlg</cstring>
8 </property> 8 </property>
9 <property stdset="1"> 9 <property stdset="1">
10 <name>geometry</name> 10 <name>geometry</name>
11 <rect> 11 <rect>
12 <x>0</x> 12 <x>0</x>
13 <y>0</y> 13 <y>0</y>
14 <width>222</width> 14 <width>218</width>
15 <height>274</height> 15 <height>274</height>
16 </rect> 16 </rect>
17 </property> 17 </property>
18 <property stdset="1"> 18 <property stdset="1">
19 <name>caption</name> 19 <name>caption</name>
20 <string>Network Time</string> 20 <string>Network Time</string>
21 </property> 21 </property>
22 <property> 22 <property>
23 <name>layoutMargin</name> 23 <name>layoutMargin</name>
24 </property> 24 </property>
25 <property> 25 <property>
26 <name>layoutSpacing</name> 26 <name>layoutSpacing</name>
27 </property> 27 </property>
28 <widget> 28 <widget>
29 <class>QTabWidget</class> 29 <class>QTabWidget</class>
30 <property stdset="1"> 30 <property stdset="1">
31 <name>name</name> 31 <name>name</name>
32 <cstring>TabWidgetMain</cstring> 32 <cstring>TabWidgetMain</cstring>
33 </property> 33 </property>
34 <property stdset="1"> 34 <property stdset="1">
35 <name>geometry</name> 35 <name>geometry</name>
36 <rect> 36 <rect>
37 <x>10</x> 37 <x>10</x>
38 <y>0</y> 38 <y>0</y>
39 <width>200</width> 39 <width>200</width>
40 <height>260</height> 40 <height>260</height>
41 </rect> 41 </rect>
42 </property> 42 </property>
43 <property> 43 <property>
44 <name>layoutMargin</name> 44 <name>layoutMargin</name>
45 </property> 45 </property>
46 <property> 46 <property>
47 <name>layoutSpacing</name> 47 <name>layoutSpacing</name>
48 </property> 48 </property>
49 <widget> 49 <widget>
50 <class>QWidget</class> 50 <class>QWidget</class>
51 <property stdset="1"> 51 <property stdset="1">
52 <name>name</name> 52 <name>name</name>
53 <cstring>tabMain</cstring> 53 <cstring>tabMain</cstring>
54 </property> 54 </property>
55 <attribute> 55 <attribute>
56 <name>title</name> 56 <name>title</name>
57 <string>Molweight</string> 57 <string>Molweight</string>
58 </attribute> 58 </attribute>
59 <widget> 59 <widget>
60 <class>QFrame</class> 60 <class>QFrame</class>
61 <property stdset="1"> 61 <property stdset="1">
62 <name>name</name> 62 <name>name</name>
63 <cstring>FrameSystemTime</cstring> 63 <cstring>FrameSystemTime</cstring>
64 </property> 64 </property>
65 <property stdset="1"> 65 <property stdset="1">
66 <name>geometry</name> 66 <name>geometry</name>
67 <rect> 67 <rect>
68 <x>2</x> 68 <x>2</x>
69 <y>2</y> 69 <y>2</y>
70 <width>180</width> 70 <width>180</width>
71 <height>220</height> 71 <height>220</height>
72 </rect> 72 </rect>
73 </property> 73 </property>
74 <property stdset="1"> 74 <property stdset="1">
75 <name>frameShape</name> 75 <name>frameShape</name>
76 <enum>StyledPanel</enum> 76 <enum>StyledPanel</enum>
77 </property> 77 </property>
78 <property stdset="1"> 78 <property stdset="1">
79 <name>frameShadow</name> 79 <name>frameShadow</name>
80 <enum>Raised</enum> 80 <enum>Raised</enum>
81 </property> 81 </property>
82 <widget> 82 <widget>
83 <class>QLabel</class> 83 <class>QLabel</class>
84 <property stdset="1"> 84 <property stdset="1">
85 <name>name</name> 85 <name>name</name>
86 <cstring>TextLabel1_4</cstring> 86 <cstring>TextLabel1_4</cstring>
87 </property> 87 </property>
88 <property stdset="1"> 88 <property stdset="1">
89 <name>geometry</name> 89 <name>geometry</name>
90 <rect> 90 <rect>
91 <x>1</x> 91 <x>1</x>
92 <y>1</y> 92 <y>1</y>
93 <width>298</width> 93 <width>298</width>
94 <height>16</height> 94 <height>16</height>
95 </rect> 95 </rect>
96 </property> 96 </property>
97 <property stdset="1"> 97 <property stdset="1">
98 <name>text</name> 98 <name>text</name>
99 <string>Formula:</string> 99 <string>Formula:</string>
100 </property> 100 </property>
101 </widget> 101 </widget>
102 <widget> 102 <widget>
103 <class>QLabel</class>
104 <property stdset="1">
105 <name>name</name>
106 <cstring>TextLabel2_4</cstring>
107 </property>
108 <property stdset="1">
109 <name>geometry</name>
110 <rect>
111 <x>1</x>
112 <y>86</y>
113 <width>298</width>
114 <height>16</height>
115 </rect>
116 </property>
117 <property stdset="1">
118 <name>text</name>
119 <string>Result:</string>
120 </property>
121 </widget>
122 <widget>
123 <class>QLayoutWidget</class> 103 <class>QLayoutWidget</class>
124 <property stdset="1"> 104 <property stdset="1">
125 <name>name</name> 105 <name>name</name>
126 <cstring>Layout7</cstring> 106 <cstring>Layout7</cstring>
127 </property> 107 </property>
128 <property stdset="1"> 108 <property stdset="1">
129 <name>geometry</name> 109 <name>geometry</name>
130 <rect> 110 <rect>
131 <x>0</x> 111 <x>0</x>
132 <y>50</y> 112 <y>50</y>
133 <width>175</width> 113 <width>175</width>
134 <height>30</height> 114 <height>30</height>
135 </rect> 115 </rect>
136 </property> 116 </property>
137 <hbox> 117 <hbox>
138 <property stdset="1"> 118 <property stdset="1">
139 <name>margin</name> 119 <name>margin</name>
140 <number>0</number> 120 <number>0</number>
141 </property> 121 </property>
142 <property stdset="1"> 122 <property stdset="1">
143 <name>spacing</name> 123 <name>spacing</name>
144 <number>6</number> 124 <number>6</number>
145 </property> 125 </property>
146 <widget> 126 <widget>
147 <class>QPushButton</class> 127 <class>QPushButton</class>
148 <property stdset="1"> 128 <property stdset="1">
149 <name>name</name> 129 <name>name</name>
150 <cstring>calculate</cstring> 130 <cstring>calculate</cstring>
151 </property> 131 </property>
152 <property stdset="1"> 132 <property stdset="1">
153 <name>text</name> 133 <name>text</name>
154 <string>Calculate</string> 134 <string>Calculate</string>
155 </property> 135 </property>
156 </widget> 136 </widget>
157 <widget> 137 <widget>
158 <class>QPushButton</class> 138 <class>QPushButton</class>
159 <property stdset="1"> 139 <property stdset="1">
160 <name>name</name> 140 <name>name</name>
161 <cstring>clear_fields</cstring> 141 <cstring>clear_fields</cstring>
162 </property> 142 </property>
163 <property stdset="1"> 143 <property stdset="1">
164 <name>text</name> 144 <name>text</name>
165 <string>Clear</string> 145 <string>Clear</string>
166 </property> 146 </property>
167 </widget> 147 </widget>
168 </hbox> 148 </hbox>
169 </widget> 149 </widget>
170 <widget> 150 <widget>
171 <class>QLineEdit</class> 151 <class>QLineEdit</class>
172 <property stdset="1"> 152 <property stdset="1">
173 <name>name</name> 153 <name>name</name>
174 <cstring>formula</cstring> 154 <cstring>formula</cstring>
175 </property> 155 </property>
176 <property stdset="1"> 156 <property stdset="1">
177 <name>geometry</name> 157 <name>geometry</name>
178 <rect> 158 <rect>
179 <x>0</x> 159 <x>0</x>
180 <y>20</y> 160 <y>20</y>
181 <width>170</width> 161 <width>170</width>
182 <height>22</height> 162 <height>22</height>
183 </rect> 163 </rect>
184 </property> 164 </property>
185 </widget> 165 </widget>
186 <widget> 166 <widget>
187 <class>QMultiLineEdit</class> 167 <class>QMultiLineEdit</class>
188 <property stdset="1"> 168 <property stdset="1">
189 <name>name</name> 169 <name>name</name>
190 <cstring>anal_display</cstring> 170 <cstring>anal_display</cstring>
191 </property> 171 </property>
192 <property stdset="1"> 172 <property stdset="1">
193 <name>geometry</name> 173 <name>geometry</name>
194 <rect> 174 <rect>
195 <x>0</x> 175 <x>0</x>
196 <y>130</y> 176 <y>130</y>
197 <width>170</width> 177 <width>170</width>
198 <height>80</height> 178 <height>80</height>
199 </rect> 179 </rect>
200 </property> 180 </property>
201 </widget> 181 </widget>
202 <widget> 182 <widget>
203 <class>QLineEdit</class> 183 <class>QLineEdit</class>
204 <property stdset="1"> 184 <property stdset="1">
205 <name>name</name> 185 <name>name</name>
206 <cstring>LineEdit2</cstring> 186 <cstring>result</cstring>
207 </property> 187 </property>
208 <property stdset="1"> 188 <property stdset="1">
209 <name>geometry</name> 189 <name>geometry</name>
210 <rect> 190 <rect>
211 <x>0</x> 191 <x>0</x>
212 <y>100</y> 192 <y>100</y>
213 <width>170</width> 193 <width>170</width>
214 <height>22</height> 194 <height>22</height>
215 </rect> 195 </rect>
216 </property> 196 </property>
217 </widget> 197 </widget>
198 <widget>
199 <class>QLabel</class>
200 <property stdset="1">
201 <name>name</name>
202 <cstring>TextLabel2_4</cstring>
203 </property>
204 <property stdset="1">
205 <name>geometry</name>
206 <rect>
207 <x>1</x>
208 <y>86</y>
209 <width>298</width>
210 <height>16</height>
211 </rect>
212 </property>
213 <property stdset="1">
214 <name>text</name>
215 <string>Result:</string>
216 </property>
217 </widget>
218 </widget> 218 </widget>
219 </widget> 219 </widget>
220 <widget> 220 <widget>
221 <class>QWidget</class> 221 <class>QWidget</class>
222 <property stdset="1"> 222 <property stdset="1">
223 <name>name</name> 223 <name>name</name>
224 <cstring>tabNtp</cstring> 224 <cstring>tabNtp</cstring>
225 </property> 225 </property>
226 <attribute> 226 <attribute>
227 <name>title</name> 227 <name>title</name>
228 <string>Nernst</string> 228 <string>Nernst</string>
229 </attribute> 229 </attribute>
230 <grid> 230 <grid>
231 <property stdset="1"> 231 <property stdset="1">
232 <name>margin</name> 232 <name>margin</name>
233 <number>1</number> 233 <number>1</number>
234 </property> 234 </property>
235 <property stdset="1"> 235 <property stdset="1">
236 <name>spacing</name> 236 <name>spacing</name>
237 <number>2</number> 237 <number>2</number>
238 </property> 238 </property>
239 </grid> 239 </grid>
240 </widget> 240 </widget>
241 </widget> 241 </widget>
242</widget> 242</widget>
243</UI> 243</UI>
diff --git a/noncore/apps/checkbook/calcdlgui.cpp b/noncore/apps/checkbook/calcdlgui.cpp
index a86374b..e9b40d3 100644
--- a/noncore/apps/checkbook/calcdlgui.cpp
+++ b/noncore/apps/checkbook/calcdlgui.cpp
@@ -1,52 +1,55 @@
1/*************************************************************************** 1/***************************************************************************
2 * * 2 * *
3 * This program is free software; you can redistribute it and/or modify * 3 * This program is free software; you can redistribute it and/or modify *
4 * it under the terms of the GNU General Public License as published by * 4 * it under the terms of the GNU General Public License as published by *
5 * the Free Software Foundation; either version 2 of the License, or * 5 * the Free Software Foundation; either version 2 of the License, or *
6 * ( at your option ) any later version. * 6 * ( at your option ) any later version. *
7 * * 7 * *
8 * ***********************************************************************/ 8 **************************************************************************/
9#include "oxygen.h" 9#include "oxygen.h"
10 10
11#include <qmenubar.h> 11#include "calcdlgui.h"
12#include <qstatusbar.h> 12#include "kmolcalc.h"
13#include <qpopupmenu.h> 13#include <qlineedit.h>
14#include <qlabel.h> 14#include <qmultilineedit.h>
15#include <qapplication.h>
16#include <qpushbutton.h> 15#include <qpushbutton.h>
17#include <qfile.h>
18#include <qdir.h>
19#include <qvbox.h>
20#include "calcdlg.h"
21 16
22Oxygen::Oxygen() 17calcDlgUI::calcDlgUI() : CalcDlg()
23 : QMainWindow()
24{ 18{
25 this->setCaption( "Oxygen" ); 19 kmolcalc = new KMolCalc;
26 vbox = new QVBox( this ); 20 connect( calculate, SIGNAL( clicked() ), this, SLOT( calc() ) );
27 QPushButton *setButton = new QPushButton( "Settings", vbox ); 21 connect( clear_fields, SIGNAL( clicked() ), this, SLOT( clear() ) );
28 connect ( setButton, SIGNAL( clicked() ), this, SLOT( slotSettings() ) );
29 QPushButton *calcButton = new QPushButton( "Calculations", vbox );
30 connect ( calcButton, SIGNAL( clicked() ), this, SLOT( slotCalculations() ) );
31 QPushButton *pseButton = new QPushButton( "PSE", vbox );
32 connect ( pseButton, SIGNAL( clicked() ), this, SLOT( slotPSE() ) );
33
34 setCentralWidget( vbox );
35} 22}
36 23
37 24void calcDlgUI::calc()
38void Oxygen::close()
39{ 25{
40 QApplication::exit(); 26 QString compound( formula->text() );
27 if ( compound.isEmpty() ) {
28 clear();
29 return;
30 }
31 QString errors( kmolcalc->readFormula( compound ) );
32 QString mw, ea;
33 double weight = kmolcalc->getWeight();
34 if ( errors == "OK" ) {
35 mw.setNum( weight );
36 ea = kmolcalc->getEmpFormula() + " :\n" + kmolcalc->getEA();
37 } else {
38 mw = "???";
39 ea = tr( "ERROR: \n" ) + errors + "\n";
40 }
41 result->setText( mw );
42 anal_display->setText( ea );
41} 43}
42 44
43//SLOTS 45/**
44 46 * * Clear all text entry / result fields.
45void Oxygen::slotCalculations(){ 47 * */
46 CalcDlgUI *calcDlgUI = new calcDlgUI(); 48void calcDlgUI::clear()
47 calcDlgUI->show(); 49{
48}; 50 formula->clear();
51 result->clear();
52 anal_display->clear();
53}
49 54
50void Oxygen::slotSettings(){ };
51void Oxygen::slotPSE(){ };
52 55
diff --git a/noncore/apps/checkbook/calcdlgui.h b/noncore/apps/checkbook/calcdlgui.h
index 1e923ee..33a1ec1 100644
--- a/noncore/apps/checkbook/calcdlgui.h
+++ b/noncore/apps/checkbook/calcdlgui.h
@@ -1,22 +1,27 @@
1 1
2#include <qpe/resource.h> 2/***************************************************************************
3#include <qmainwindow.h> 3 * *
4#include <qtoolbar.h> 4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * ( at your option ) any later version. *
8 * *
9 **************************************************************************/
5#include <qstring.h> 10#include <qstring.h>
6#include <qpopupmenu.h> 11#include "calcdlg.h"
7 12
8class QVBox; 13class QVBox;
14class KMolCalc;
9 15
10class Oxygen : public QMainWindow 16class calcDlgUI : public CalcDlg
11{ 17{
12 Q_OBJECT 18 Q_OBJECT
13 19
14 public: 20 public:
15 Oxygen(); 21 calcDlgUI();
16 QVBox *vbox; 22 KMolCalc *kmolcalc;
17 private slots: 23
18 void slotCalculations(); 24 public slots:
19 void slotSettings(); 25 void calc();
20 void slotPSE(); 26 void clear();
21 void close();
22}; 27};
diff --git a/noncore/apps/checkbook/kmolcalc.cpp b/noncore/apps/checkbook/kmolcalc.cpp
index e5ab736..50e1375 100644
--- a/noncore/apps/checkbook/kmolcalc.cpp
+++ b/noncore/apps/checkbook/kmolcalc.cpp
@@ -1,233 +1,235 @@
1/* 1/*
2 * kmolcalc.cpp 2 * kmolcalc.cpp
3 * 3 *
4 * Copyright (C) 2000 Tomislav Gountchev <tomi@idiom.com> 4 * Copyright (C) 2000 Tomislav Gountchev <tomi@idiom.com>
5 * Copyright (C) 2002 Carsten Niehaus <cniehaus@handhelds.org>
5 */ 6 */
6 7
7/** 8/**
8 * KMOLCALC is the calculation engine. It knows about a hashtable of user defined atomic 9 * KMOLCALC is the calculation engine. It knows about a hashtable of user defined atomic
9 * weights and group definitions ELSTABLE, and the currently processed formula, stored 10 * weights and group definitions ELSTABLE, and the currently processed formula, stored
10 * as a list of elements and their coefficients, ELEMENTS. 11 * as a list of elements and their coefficients, ELEMENTS.
11 */ 12 */
12 13
13#include "kmolcalc.h" 14#include "kmolcalc.h"
14#include <qdict.h> 15#include <qdict.h>
15#include <qdir.h> 16#include <qdir.h>
17#include <qfile.h>
16#include <iostream.h> 18#include <iostream.h>
17 19
18 20
19/** 21/**
20 * Construct a new calculator object. 22 * Construct a new calculator object.
21 */ 23 */
22KMolCalc::KMolCalc() { 24KMolCalc::KMolCalc() {
23 elements = new ElementList; 25 elements = new ElementList;
24 elstable = NULL; 26 elstable = NULL;
25 readElstable(); 27 readElstable();
26} 28}
27 29
28KMolCalc::~KMolCalc() { 30KMolCalc::~KMolCalc() {
29 delete elements; 31 delete elements;
30} 32}
31 33
32void KMolCalc::readElstable() { 34void KMolCalc::readElstable() {
33 weight = -1; // not calculated yet 35 weight = -1; // not calculated yet
34 if (elstable) delete elstable; 36 if (elstable) delete elstable;
35 elstable = new QDict<SubUnit> (197, TRUE); 37 elstable = new QDict<SubUnit> (197, TRUE);
36 elstable->setAutoDelete(TRUE); 38 elstable->setAutoDelete(TRUE);
37 QStringList files;// = // KGlobal::dirs()->findAllResources("appdata", "kmolweights"); 39 QStringList files;// = // KGlobal::dirs()->findAllResources("appdata", "kmolweights");
38// mwfile = locateLocal("data", "kmol")+"/kmolweights"; 40 mwfile = "/home/opie/opie/noncore/apps/oxigen/kmolweights";
39 QFile f(mwfile); 41 QFile f(mwfile);
40 QString* latest_f = &mwfile; 42 QString* latest_f = &mwfile;
41 for (uint i=0; i<files.count(); i++) { 43 for (uint i=0; i<files.count(); i++) {
42 if (QFileInfo(QFile(files[i])).lastModified() > QFileInfo(QFile(*latest_f)).lastModified()) { 44 if (QFileInfo(QFile(files[i])).lastModified() > QFileInfo(QFile(*latest_f)).lastModified()) {
43 latest_f = &files[i]; 45 latest_f = &files[i];
44 } 46 }
45 } 47 }
46 QFile lf(*latest_f); 48 QFile lf(*latest_f);
47 if (f.exists()) readMwfile(f); 49 if (f.exists()) readMwfile(f);
48 if (!f.exists()) { 50 if (!f.exists()) {
49 readMwfile(lf); 51 readMwfile(lf);
50 writeElstable(); 52 writeElstable();
51 } else if (QFileInfo(f).lastModified() < QFileInfo(lf).lastModified()) { 53 } else if (QFileInfo(f).lastModified() < QFileInfo(lf).lastModified()) {
52 // announce 54 // announce
53 QMessageBox::information 55 QMessageBox::information
54 (0, "Warning:", "Found new global Mw file.\nLocal definitions will be updated.", QMessageBox::Ok); 56 (0, "Warning:", "Found new global Mw file.\nLocal definitions will be updated.", QMessageBox::Ok);
55 readMwfile(lf); 57 readMwfile(lf);
56 writeElstable(); 58 writeElstable();
57 } 59 }
58 60
59} 61}
60 62
61 63
62/** 64/**
63 * Parse a string S and construct the ElementList this->ELEMENTS, representing the 65 * Parse a string S and construct the ElementList this->ELEMENTS, representing the
64 * composition of S. Returns 0 if successful, or an error code (currently -1) if 66 * composition of S. Returns 0 if successful, or an error code (currently -1) if
65 * parsing failed. 67 * parsing failed.
66 * The elements is S must be valid element or group symbols, as stored in this->ELSTABLE. 68 * The elements is S must be valid element or group symbols, as stored in this->ELSTABLE.
67 * See help files for correct formula syntax. 69 * See help files for correct formula syntax.
68 */ 70 */
69QString KMolCalc::readFormula(const QString& s) { 71QString KMolCalc::readFormula(const QString& s) {
70 weight = -1; 72 weight = -1;
71 if (elements) delete elements; 73 if (elements) delete elements;
72 elements = new ElementList; 74 elements = new ElementList;
73 return KMolCalc::readGroup(s, elements); 75 return KMolCalc::readGroup(s, elements);
74} 76}
75 77
76// read a formula group recursively. Called by readFormula. 78// read a formula group recursively. Called by readFormula.
77QString KMolCalc::readGroup(const QString& s, ElementList* els) { 79QString KMolCalc::readGroup(const QString& s, ElementList* els) {
78 if (s.isEmpty()) return QString ("Enter a formula."); //ERROR 80 if (s.isEmpty()) return QString ("Enter a formula."); //ERROR
79 int sl = s.length(); 81 int sl = s.length();
80 int i = 0; 82 int i = 0;
81 QString errors ("OK"); 83 QString errors ("OK");
82 bool ok = TRUE; 84 bool ok = TRUE;
83 while (i < sl && ((s[i] <= '9' && s[i] >= '0') || s[i] == '.')) i++; 85 while (i < sl && ((s[i] <= '9' && s[i] >= '0') || s[i] == '.')) i++;
84 double prefix = (i == 0 ? 1 : s.left(i).toDouble(&ok)); 86 double prefix = (i == 0 ? 1 : s.left(i).toDouble(&ok));
85 if (! ok || i == sl || prefix == 0) return QString ("Bad formula."); // ERROR 87 if (! ok || i == sl || prefix == 0) return QString ("Bad formula."); // ERROR
86 ElementList* elstemp = new ElementList; 88 ElementList* elstemp = new ElementList;
87 while (i < sl) { 89 while (i < sl) {
88 int j = i; 90 int j = i;
89 if (s[i] == '(') { 91 if (s[i] == '(') {
90 ElementList* inner = new ElementList; 92 ElementList* inner = new ElementList;
91 int level = 1; // count levels of nested ( ). 93 int level = 1; // count levels of nested ( ).
92 while (1) { 94 while (1) {
93 if (i++ == sl) { 95 if (i++ == sl) {
94 delete inner; 96 delete inner;
95 delete elstemp; 97 delete elstemp;
96 return QString ("Bad formula."); //ERROR 98 return QString ("Bad formula."); //ERROR
97 } 99 }
98 if (s[i] == '(') level++; 100 if (s[i] == '(') level++;
99 if (s[i] == ')') level--; 101 if (s[i] == ')') level--;
100 if (level == 0) break; 102 if (level == 0) break;
101 } 103 }
102 errors = KMolCalc::readGroup(s.mid(j+1, i-j-1), inner); 104 errors = KMolCalc::readGroup(s.mid(j+1, i-j-1), inner);
103 j = ++i; 105 j = ++i;
104 while (i < sl && ((s[i] <= '9' && s[i] >= '0') || s[i] == '.')) i++; 106 while (i < sl && ((s[i] <= '9' && s[i] >= '0') || s[i] == '.')) i++;
105 double suffix = (i == j ? 1 : s.mid(j, i-j).toDouble(&ok)); 107 double suffix = (i == j ? 1 : s.mid(j, i-j).toDouble(&ok));
106 if (! ok || suffix == 0) { 108 if (! ok || suffix == 0) {
107 delete inner; 109 delete inner;
108 delete elstemp; 110 delete elstemp;
109 return QString ("Bad formula."); // ERROR 111 return QString ("Bad formula."); // ERROR
110 } 112 }
111 inner->addTo(*elstemp, suffix); 113 inner->addTo(*elstemp, suffix);
112 delete inner; 114 delete inner;
113 inner = NULL; 115 inner = NULL;
114 } else if ((s[i] >= 'A' && s[i] <= 'Z') || (s[i] >= 'a' && s[i] <= 'z')) { 116 } else if ((s[i] >= 'A' && s[i] <= 'Z') || (s[i] >= 'a' && s[i] <= 'z')) {
115 while (++i < sl && ((s[i] >= 'a' && s[i] <= 'z') || s[i] == '*' || 117 while (++i < sl && ((s[i] >= 'a' && s[i] <= 'z') || s[i] == '*' ||
116 s[i] == '\'')); 118 s[i] == '\''));
117 QString elname = s.mid(j, i-j); 119 QString elname = s.mid(j, i-j);
118 j = i; 120 j = i;
119 while (i < sl && ((s[i] <= '9' && s[i] >= '0') || s[i] == '.')) i++; 121 while (i < sl && ((s[i] <= '9' && s[i] >= '0') || s[i] == '.')) i++;
120 double suffix = (i == j ? 1 : s.mid(j, i-j).toDouble(&ok)); 122 double suffix = (i == j ? 1 : s.mid(j, i-j).toDouble(&ok));
121 if (! ok || suffix == 0) { 123 if (! ok || suffix == 0) {
122 delete elstemp; 124 delete elstemp;
123 return QString ("Bad formula."); // ERROR 125 return QString ("Bad formula."); // ERROR
124 } 126 }
125 SubUnit* group = elstable->find(elname); 127 SubUnit* group = elstable->find(elname);
126 if (group == 0) { 128 if (group == 0) {
127 delete elstemp; 129 delete elstemp;
128 return QString ("Undefined symbol: ") + elname; //ERROR 130 return QString ("Undefined symbol: ") + elname; //ERROR
129 } 131 }
130 group->addTo(*elstemp, suffix); 132 group->addTo(*elstemp, suffix);
131 } else if (s[i] == '+') { 133 } else if (s[i] == '+') {
132 if (elstemp->isEmpty()) { 134 if (elstemp->isEmpty()) {
133 delete elstemp; 135 delete elstemp;
134 return QString ("Bad formula."); //ERROR 136 return QString ("Bad formula."); //ERROR
135 } 137 }
136 elstemp->addTo(*els, prefix); 138 elstemp->addTo(*els, prefix);
137 delete elstemp; 139 delete elstemp;
138 errors = KMolCalc::readGroup(s.mid(i+1, sl-i-1), els); 140 errors = KMolCalc::readGroup(s.mid(i+1, sl-i-1), els);
139 return errors; 141 return errors;
140 } else { 142 } else {
141 delete elstemp; 143 delete elstemp;
142 return QString ("Bad formula."); //ERROR 144 return QString ("Bad formula."); //ERROR
143 } 145 }
144 } 146 }
145 elstemp->addTo(*els, prefix); 147 elstemp->addTo(*els, prefix);
146 delete elstemp; 148 delete elstemp;
147 return errors; 149 return errors;
148} 150}
149 151
150/** 152/**
151 * Calculate and return the molecular weight of the current chemical formula. 153 * Calculate and return the molecular weight of the current chemical formula.
152 */ 154 */
153double KMolCalc::getWeight() { 155double KMolCalc::getWeight() {
154 if (weight == -1) weight = elements->getWeight(elstable); 156 if (weight == -1) weight = elements->getWeight(elstable);
155 return weight; 157 return weight;
156} 158}
157 159
158/** 160/**
159 * Return the elemental composition of the current formula, as a string of tab-separated 161 * Return the elemental composition of the current formula, as a string of tab-separated
160 * element - percentage pairs, separated by newlines. 162 * element - percentage pairs, separated by newlines.
161 */ 163 */
162QString KMolCalc::getEA() { 164QString KMolCalc::getEA() {
163 if (weight == -1) weight = elements->getWeight(elstable); 165 if (weight == -1) weight = elements->getWeight(elstable);
164 if (weight == -1) return QString("ERROR: Couldn't get Mw..."); // ERROR 166 if (weight == -1) return QString("ERROR: Couldn't get Mw..."); // ERROR
165 return elements->getEA(elstable, weight); 167 return elements->getEA(elstable, weight);
166} 168}
167 169
168/** 170/**
169 * Return the empirical formula of the current compound as a QString. 171 * Return the empirical formula of the current compound as a QString.
170 */ 172 */
171QString KMolCalc::getEmpFormula() { 173QString KMolCalc::getEmpFormula() {
172 return elements->getEmpFormula(); 174 return elements->getEmpFormula();
173} 175}
174 176
175// Read the element definition file. 177// Read the element definition file.
176void KMolCalc::readMwfile(QFile& f) { 178void KMolCalc::readMwfile(QFile& f) {
177 if (! f.open(IO_ReadOnly)) return; //ERROR 179 if (! f.open(IO_ReadOnly)) return; //ERROR
178 QTextStream fs (&f); 180 QTextStream fs (&f);
179 QString line; 181 QString line;
180 while (! fs.eof()) { 182 while (! fs.eof()) {
181 line = fs.readLine(); 183 line = fs.readLine();
182 SubUnit* s = SubUnit::makeSubUnit(line); 184 SubUnit* s = SubUnit::makeSubUnit(line);
183 elstable->replace(s->getName(), s); 185 elstable->replace(s->getName(), s);
184 } 186 }
185 f.close(); 187 f.close();
186} 188}
187 189
188/** 190/**
189 * Save the element definitions file. 191 * Save the element definitions file.
190 */ 192 */
191void KMolCalc::writeElstable() { 193void KMolCalc::writeElstable() {
192 QFile f(mwfile); 194 QFile f(mwfile);
193 if (! f.open(IO_WriteOnly)) return; //ERROR 195 if (! f.open(IO_WriteOnly)) return; //ERROR
194 QTextStream fs (&f); 196 QTextStream fs (&f);
195 QString line; 197 QString line;
196 QDictIterator<SubUnit> it(*elstable); 198 QDictIterator<SubUnit> it(*elstable);
197 while (it.current()) { 199 while (it.current()) {
198 it.current()->writeOut(line); 200 it.current()->writeOut(line);
199 fs << line << endl; 201 fs << line << endl;
200 ++it; 202 ++it;
201 } 203 }
202 f.close(); 204 f.close();
203} 205}
204 206
205/** 207/**
206 * Remove a group or element definition from ELSTABLE. 208 * Remove a group or element definition from ELSTABLE.
207 */ 209 */
208void KMolCalc::undefineGroup (const QString& name) { 210void KMolCalc::undefineGroup (const QString& name) {
209 elstable->remove (name); 211 elstable->remove (name);
210} 212}
211 213
212/** 214/**
213 * Add a new element name - atomic weight record to the ELSTABLE hashtable. Assumes 215 * Add a new element name - atomic weight record to the ELSTABLE hashtable. Assumes
214 * NAME has valid syntax. 216 * NAME has valid syntax.
215 217
216 */ 218 */
217void KMolCalc::defineElement (const QString& name, double weight) { 219void KMolCalc::defineElement (const QString& name, double weight) {
218 Element* el = new Element(name, weight); 220 Element* el = new Element(name, weight);
219 elstable->replace(name, el); 221 elstable->replace(name, el);
220} 222}
221 223
222/** 224/**
223 * Add a new group definition to the ELSTABLE. Returns 0 if OK, -1 if parsing FORMULA 225 * Add a new group definition to the ELSTABLE. Returns 0 if OK, -1 if parsing FORMULA
224 * fails. Assumes the syntax of grpname is correct. 226 * fails. Assumes the syntax of grpname is correct.
225 */ 227 */
226QString KMolCalc::defineGroup (const QString& grpname, const QString& formula) { 228QString KMolCalc::defineGroup (const QString& grpname, const QString& formula) {
227 ElementList* els = new ElementList(grpname); 229 ElementList* els = new ElementList(grpname);
228 QString error = readGroup(formula, els); 230 QString error = readGroup(formula, els);
229 if (error != "OK") return error; 231 if (error != "OK") return error;
230 if (els->contains(grpname)) return QString("Can't define a group recursively!\n"); 232 if (els->contains(grpname)) return QString("Can't define a group recursively!\n");
231 elstable->replace(grpname, els); 233 elstable->replace(grpname, els);
232 return QString("OK"); 234 return QString("OK");
233} 235}
diff --git a/noncore/apps/checkbook/oxygen.cpp b/noncore/apps/checkbook/oxygen.cpp
index a86374b..81897e9 100644
--- a/noncore/apps/checkbook/oxygen.cpp
+++ b/noncore/apps/checkbook/oxygen.cpp
@@ -1,52 +1,53 @@
1/*************************************************************************** 1/***************************************************************************
2 * * 2 * *
3 * This program is free software; you can redistribute it and/or modify * 3 * This program is free software; you can redistribute it and/or modify *
4 * it under the terms of the GNU General Public License as published by * 4 * it under the terms of the GNU General Public License as published by *
5 * the Free Software Foundation; either version 2 of the License, or * 5 * the Free Software Foundation; either version 2 of the License, or *
6 * ( at your option ) any later version. * 6 * ( at your option ) any later version. *
7 * * 7 * *
8 * ***********************************************************************/ 8 * ***********************************************************************/
9#include "oxygen.h" 9#include "oxygen.h"
10 10
11#include <qmenubar.h> 11#include <qmenubar.h>
12#include <qstatusbar.h> 12#include <qstatusbar.h>
13#include <qpopupmenu.h> 13#include <qpopupmenu.h>
14#include <qlabel.h> 14#include <qlabel.h>
15#include <qapplication.h> 15#include <qapplication.h>
16#include <qpushbutton.h> 16#include <qpushbutton.h>
17#include <qfile.h> 17#include <qfile.h>
18#include <qdir.h> 18#include <qdir.h>
19#include <qvbox.h> 19#include <qvbox.h>
20#include "calcdlg.h" 20#include "calcdlg.h"
21#include "calcdlgui.h"
21 22
22Oxygen::Oxygen() 23Oxygen::Oxygen()
23 : QMainWindow() 24 : QMainWindow()
24{ 25{
25 this->setCaption( "Oxygen" ); 26 this->setCaption( "Oxygen" );
26 vbox = new QVBox( this ); 27 vbox = new QVBox( this );
27 QPushButton *setButton = new QPushButton( "Settings", vbox ); 28 QPushButton *setButton = new QPushButton( "Settings", vbox );
28 connect ( setButton, SIGNAL( clicked() ), this, SLOT( slotSettings() ) ); 29 connect ( setButton, SIGNAL( clicked() ), this, SLOT( slotSettings() ) );
29 QPushButton *calcButton = new QPushButton( "Calculations", vbox ); 30 QPushButton *calcButton = new QPushButton( "Calculations", vbox );
30 connect ( calcButton, SIGNAL( clicked() ), this, SLOT( slotCalculations() ) ); 31 connect ( calcButton, SIGNAL( clicked() ), this, SLOT( slotCalculations() ) );
31 QPushButton *pseButton = new QPushButton( "PSE", vbox ); 32 QPushButton *pseButton = new QPushButton( "PSE", vbox );
32 connect ( pseButton, SIGNAL( clicked() ), this, SLOT( slotPSE() ) ); 33 connect ( pseButton, SIGNAL( clicked() ), this, SLOT( slotPSE() ) );
33 34
34 setCentralWidget( vbox ); 35 setCentralWidget( vbox );
35} 36}
36 37
37 38
38void Oxygen::close() 39void Oxygen::close()
39{ 40{
40 QApplication::exit(); 41 QApplication::exit();
41} 42}
42 43
43//SLOTS 44//SLOTS
44 45
45void Oxygen::slotCalculations(){ 46void Oxygen::slotCalculations(){
46 CalcDlgUI *calcDlgUI = new calcDlgUI(); 47 calcDlgUI *CalcDlgUI = new calcDlgUI();
47 calcDlgUI->show(); 48 CalcDlgUI->show();
48}; 49};
49 50
50void Oxygen::slotSettings(){ }; 51void Oxygen::slotSettings(){ };
51void Oxygen::slotPSE(){ }; 52void Oxygen::slotPSE(){ };
52 53
diff --git a/noncore/apps/checkbook/oxygen.pro b/noncore/apps/checkbook/oxygen.pro
index f8e0197..c5448e7 100644
--- a/noncore/apps/checkbook/oxygen.pro
+++ b/noncore/apps/checkbook/oxygen.pro
@@ -1,18 +1,20 @@
1 TEMPLATE= app 1 TEMPLATE= app
2 CONFIG = qt warn_on release 2 CONFIG = qt warn_on release
3 HEADERS = oxygen.h \ 3 HEADERS = oxygen.h \
4 kmolcalc.h \ 4 kmolcalc.h \
5 kmolelements.h 5 kmolelements.h \
6 calcdlgui.h
6 7
7 SOURCES = main.cpp \ 8 SOURCES = main.cpp \
8 oxygen.cpp \ 9 oxygen.cpp \
9 kmolcalc.cpp \ 10 kmolcalc.cpp \
11 calcdlgui.cpp \
10 kmolelements.cpp 12 kmolelements.cpp
11INCLUDEPATH += $(OPIEDIR)/include 13INCLUDEPATH += $(OPIEDIR)/include
12DEPENDPATH += $(OPIEDIR)/include 14DEPENDPATH += $(OPIEDIR)/include
13 LIBS += -lqpe 15 LIBS += -lqpe
14 INTERFACES= calcdlg.ui 16 INTERFACES= calcdlg.ui
15 TARGET = oxygen 17 TARGET = oxygen
16 DESTDIR = $(OPIEDIR)/bin 18 DESTDIR = $(OPIEDIR)/bin
17 19
18TRANSLATIONS = ../../../i18n/de/oxygen.ts 20TRANSLATIONS = ../../../i18n/de/oxygen.ts