157 qDebug() << Q_FUNC_INFO; |
157 qDebug() << Q_FUNC_INFO; |
158 edit(-1); |
158 edit(-1); |
159 } |
159 } |
160 |
160 |
161 |
161 |
|
162 void InventoryHops::on_exportButton_clicked() |
|
163 { |
|
164 qDebug() << Q_FUNC_INFO; |
|
165 |
|
166 QSqlQuery query("SELECT * FROM inventory_hops ORDER BY origin,name"); |
|
167 const QStringList types({ "Bittering", "Aroma", "Both" }); |
|
168 const QStringList forms({ "Pellet", "Plug", "Leaf", "Leaf", "Pellet" }); |
|
169 /* "Leaf Wet", "Cryo" */ |
|
170 /* We use more hp forms then beerxml knows about, so we send known names */ |
|
171 /* instead of what we internally use. */ |
|
172 |
|
173 QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"), QDir::homePath() + "/hops.xml", tr("Files (*.xml)")); |
|
174 if (fileName == 0) { |
|
175 QMessageBox::warning(this, tr("Save File"), tr("No XML file selected.")); |
|
176 return; |
|
177 } |
|
178 |
|
179 QFile file(fileName); |
|
180 file.open(QIODevice::WriteOnly); |
|
181 |
|
182 QXmlStreamWriter *xmlWriter = new QXmlStreamWriter(&file); |
|
183 xmlWriter->writeStartDocument(); |
|
184 xmlWriter->setAutoFormatting(true); |
|
185 xmlWriter->setAutoFormattingIndent(1); |
|
186 xmlWriter->writeStartElement("HOPS"); |
|
187 |
|
188 query.first(); |
|
189 for (int i = 0 ; i < query.size() ; i++ ) { |
|
190 xmlWriter->writeStartElement("HOP"); |
|
191 xmlWriter->writeTextElement("VERSION", "1"); |
|
192 xmlWriter->writeTextElement("NAME", query.value(1).toString()); |
|
193 if (query.value(11).toString().length()) |
|
194 xmlWriter->writeTextElement("NOTES", query.value(11).toString()); |
|
195 xmlWriter->writeTextElement("ALWAYS_ON_STOCK", query.value(14).toInt() ? "TRUE":"FALSE"); |
|
196 xmlWriter->writeTextElement("ALPHA", QString::number(query.value(2).toDouble(), 'f', 4)); |
|
197 xmlWriter->writeTextElement("BETA", QString::number(query.value(3).toDouble(), 'f', 4)); |
|
198 xmlWriter->writeTextElement("HUMULENE", QString::number(query.value(4).toDouble(), 'f', 4)); |
|
199 xmlWriter->writeTextElement("CAROPHYLLENE", QString::number(query.value(5).toDouble(), 'f', 4)); |
|
200 xmlWriter->writeTextElement("COHUMULONE", QString::number(query.value(6).toDouble(), 'f', 4)); |
|
201 xmlWriter->writeTextElement("MYRCENE", QString::number(query.value(7).toDouble(), 'f', 4)); |
|
202 xmlWriter->writeTextElement("TOTAL_OIL", QString::number(query.value(19).toDouble(), 'f', 4)); |
|
203 xmlWriter->writeTextElement("HSI", QString::number(query.value(8).toDouble(), 'f', 4)); |
|
204 xmlWriter->writeTextElement("TYPE", types[query.value(9).toInt()]); |
|
205 xmlWriter->writeTextElement("FORM", forms[query.value(10).toInt()]); |
|
206 xmlWriter->writeTextElement("ORIGIN", query.value(12).toString()); |
|
207 if (query.value(13).toString().length()) |
|
208 xmlWriter->writeTextElement("SUBSTITUTES", query.value(13).toString()); |
|
209 if (query.value(16).toDouble() > 0) |
|
210 xmlWriter->writeTextElement("COST", QString::number(query.value(16).toDouble(), 'f', 4)); |
|
211 xmlWriter->writeEndElement(); |
|
212 query.next(); |
|
213 } |
|
214 |
|
215 xmlWriter->writeEndElement(); |
|
216 xmlWriter->writeEndDocument(); |
|
217 QMessageBox::information(this, tr("Save File"), tr("XML export ready")); |
|
218 |
|
219 file.close(); |
|
220 } |
|
221 |
|
222 |
162 void InventoryHops::on_quitButton_clicked() |
223 void InventoryHops::on_quitButton_clicked() |
163 { |
224 { |
164 emit firstWindow(); |
225 emit firstWindow(); |
165 } |
226 } |
166 |
227 |