src/InventoryFermentables.cpp

changeset 42
88e827ea7172
parent 34
5510352432f5
child 43
26910c149073
equal deleted inserted replaced
41:dc4b659a320b 42:88e827ea7172
140 qDebug() << Q_FUNC_INFO; 140 qDebug() << Q_FUNC_INFO;
141 edit(-1); 141 edit(-1);
142 } 142 }
143 143
144 144
145 void InventoryFermentables::on_exportButton_clicked()
146 {
147 qDebug() << Q_FUNC_INFO;
148
149 QSqlQuery query("SELECT * FROM inventory_fermentables ORDER BY supplier,name");
150 const QStringList types({"Grain", "Sugar", "Extract", "Dry extract", "Adjunct"});
151 const QStringList graintypes({"Base", "Roast", "Crystal", "Kilned", "Sour Malt", "Special", "No malt"});
152 const QStringList added({"Mash", "Boil", "Fermentation", "Lagering", "Bottle"});
153
154 QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"), "", tr("Files (*.xml)"));
155 if (fileName == 0) {
156 QMessageBox::warning(this, tr("Save File"), tr("No XML file selected."));
157 return;
158 }
159
160 QFile file(fileName);
161 file.open(QIODevice::WriteOnly);
162
163 QXmlStreamWriter *xmlWriter = new QXmlStreamWriter(&file);
164 xmlWriter->writeStartDocument();
165 xmlWriter->setAutoFormatting(true);
166 xmlWriter->writeStartElement("FERMENTABLES");
167
168 query.first();
169 for (int i = 0 ; i < query.size() ; i++ ) {
170 xmlWriter->writeStartElement("FERMENTABLE");
171 xmlWriter->writeTextElement("VERSION", "1");
172 xmlWriter->writeTextElement("NAME", query.value(1).toString());
173 xmlWriter->writeTextElement("NOTES", query.value(8).toString());
174 xmlWriter->writeTextElement("TYPE", types[query.value(2).toInt()]);
175 xmlWriter->writeTextElement("YIELD", QString::number(query.value(3).toDouble(), 'f', 5));
176 xmlWriter->writeTextElement("COLOR", QString::number(Utils::ebc_to_srm(query.value(4).toDouble()), 'f', 3) );
177 xmlWriter->writeTextElement("ADD_AFTER_BOIL", query.value(5).toInt() ? "TRUE":"FALSE");
178 xmlWriter->writeTextElement("ORIGIN", query.value(6).toString());
179 xmlWriter->writeTextElement("SUPPLIER", query.value(7).toString());
180 if (query.value(9).toDouble() > 0)
181 xmlWriter->writeTextElement("COARSE_FINE_DIFF", QString::number(query.value(9).toDouble(), 'f', 4));
182 if (query.value(10).toDouble() > 0)
183 xmlWriter->writeTextElement("MOISTURE", QString::number(query.value(10).toDouble(), 'f', 4));
184 if (query.value(11).toDouble() > 0)
185 xmlWriter->writeTextElement("DIASTATIC_POWER", QString::number(query.value(11).toDouble(), 'f', 4));
186 if (query.value(12).toDouble() > 0)
187 xmlWriter->writeTextElement("PROTEIN", QString::number(query.value(12).toDouble(), 'f', 4));
188 if (query.value(14).toDouble() > 0)
189 xmlWriter->writeTextElement("MAX_IN_BATCH", QString::number(query.value(14).toDouble(), 'f', 3));
190 xmlWriter->writeTextElement("RECOMMEND_MASH", query.value(15).toInt() ? "TRUE":"FALSE");
191 xmlWriter->writeTextElement("DISPLAY_COLOR", QString("%1 EBC").arg(query.value(4).toDouble(), 1, 'f', 0));
192 xmlWriter->writeTextElement("GRAINTYPE", graintypes[query.value(20).toInt()]);
193 xmlWriter->writeTextElement("ADDED", added[query.value(17).toInt()]);
194 if (query.value(18).toDouble() > 0)
195 xmlWriter->writeTextElement("DI_pH", QString::number(query.value(18).toDouble(), 'f', 5));
196 if (query.value(19).toDouble() > 0)
197 xmlWriter->writeTextElement("ACID_TO_pH_5.7", QString::number(query.value(19).toDouble(), 'f', 5));
198
199 xmlWriter->writeEndElement();
200 query.next();
201 }
202
203 xmlWriter->writeEndElement();
204 xmlWriter->writeEndDocument();
205 QMessageBox::warning(this, tr("Save File"), tr("XML export ready"));
206
207 file.close();
208 }
209
210
145 void InventoryFermentables::on_quitButton_clicked() 211 void InventoryFermentables::on_quitButton_clicked()
146 { 212 {
147 emit firstWindow(); 213 emit firstWindow();
148 } 214 }
149 215

mercurial