1 /***************************************************************************
3 * Sedbuk.h Copyright (C) 2008 by Jon Rumble *
4 * j.w.rumble@reading.ac.uk *
6 * This file is part of HECS, *
8 * HECS is free software: you can redistribute it and/or modify *
9 * it under the terms of the GNU General Public License as published by *
10 * the Free Software Foundation, either version 2 of the License, or *
11 * (at your option) any later version. *
13 * HECS is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU General Public License for more details. *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19 * You should have received a copy of the GNU General Public License *
20 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
21 ***************************************************************************/
26 SedbukList::SedbukList(const QString fileNameIn
) {
27 fileName
= fileNameIn
;
32 SedbukList::~SedbukList() {
35 void SedbukList::openFile(QString fileName
)
39 if (!file
.open(QIODevice::ReadOnly
| QIODevice::Text
)) {
40 std::cerr
<< "Cannot open file for reading: "
41 << qPrintable(file
.errorString())
47 QTextStream
in (&file
);
49 QString out
= in
.readLine();
50 if (out
.startsWith("$001"))
53 else if (out
.startsWith("$103"))
58 if (out
.startsWith("#"))
60 if (out
.startsWith("$"))
63 parseBoilerTable(out
);
65 }while (!out
.startsWith("$121"));
68 else if (out
.startsWith("#"))
71 else if (out
.startsWith("$999"))
85 bool SedbukList::get_sedbukAvail ()
90 Boiler
SedbukList::findBoiler (const QString
& modelStr
)
92 QString Junk
= modelStr
;
94 if (!boilerHash
.contains(modelStr
))
97 currBoiler
= boilerHash
[modelStr
];
104 QStringList
SedbukList::getBrandList(int fuel_type
)
112 //entries = buildBoilerList(gasBoilers);
115 //entries = buildBoilerList(lpgBoilers);
118 //entries = buildBoilerList(oilBoilers);
127 QStringList
SedbukList::getModelList(QString brandNameIn
)
130 QHashIterator
<QString
, Boiler
> i (boilerHash
);
137 if ((entry
.get_brandName() == brandNameIn
) && (entry
.get_fuelType() == m_fuelType
))
138 listIn
<< entry
.get_modelName() + entry
.get_modelQualifier();
147 QString
SedbukList::get_revisionDate()
149 return m_revisionDate
;
152 QStringList
SedbukList::getBoilerBrands (int fuel_type
)
155 m_fuelType
= fuel_type
;
157 QHashIterator
<QString
, Boiler
> i (boilerHash
);
164 if (entry
.get_fuelType() == m_fuelType
)
165 listIn
<< entry
.get_brandName();
171 return pruneDuplicates(listIn
);
175 void SedbukList::initVars()
183 void SedbukList::parseVersion(QString versionString
) {
184 QStringList versionInfo
;
186 m_revisionNum
= versionString
.section(",",1,1).toInt();
187 m_day
= versionString
.section(",",4,4).toInt();
188 m_month
= versionString
.section(",",3,3).toInt();
189 m_year
= versionString
.section(",",2,2).toInt();
190 m_revisionDate
= versionString
.section(",",4,4) + "/" +
191 versionString
.section(",",3,3)+ "/" +
192 versionString
.section(",",2,2);
196 void SedbukList::parseBoilerTable(QString parseStr
)
198 int str
= 0, f5
=0, f4
=0;
199 QString f1
, f2
, f3
, id
;
201 QStringList record
= parseStr
.split(",");
202 QVector
<QString
> line
= record
.toVector();
204 str
= line
[0].toInt();
208 f4
= line
[20].toDouble();
209 f5
= line
[9].toInt();
210 Boiler
tmp(str
,f1
,f2
,f3
,f4
,f5
);
211 id
= tmp
.get_modelName() + tmp
.get_modelQualifier();
212 boilerHash
.insert(id
,tmp
);
215 //qDebug("" + id.toLatin1());
218 void SedbukList::updateSedbukDatabase()