src/InventoryMiscs.cpp

changeset 45
4024b389f689
parent 28
93a70b1502ca
child 71
5bd0d7be0167
equal deleted inserted replaced
44:5a9a159c2d34 45:4024b389f689
145 qDebug() << Q_FUNC_INFO; 145 qDebug() << Q_FUNC_INFO;
146 edit(-1); 146 edit(-1);
147 } 147 }
148 148
149 149
150 void InventoryMiscs::on_exportButton_clicked()
151 {
152 qDebug() << Q_FUNC_INFO;
153
154 QSqlQuery query("SELECT * FROM inventory_miscs ORDER BY name");
155 const QStringList types({ "Spice", "Herb", "Flavor", "Fining", "Water agent", "Other", "Other" });
156 /* 'Spice', 'Herb', 'Flavor', 'Fining', 'Water agent', 'Yeast nutrient', 'Other' */
157 /* We use more misc types then beerxml knows about, so we send known names */
158 /* instead of what we internally use. */
159 const QStringList uses({ "Secondary", "Mash", "Boil", "Primary", "Secondary", "Bottling" });
160 /* 'Starter', 'Mash', 'Boil', 'Primary', 'Secondary', 'Bottling' */
161 /* Stupid beerxml leaves us no other choice then to map a starter ingredient to secondary */
162
163 QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"), QDir::homePath() + "/miscs.xml", tr("Files (*.xml)"));
164 if (fileName == 0) {
165 QMessageBox::warning(this, tr("Save File"), tr("No XML file selected."));
166 return;
167 }
168
169 QFile file(fileName);
170 file.open(QIODevice::WriteOnly);
171
172 QXmlStreamWriter *xmlWriter = new QXmlStreamWriter(&file);
173 xmlWriter->writeStartDocument();
174 xmlWriter->setAutoFormatting(true);
175 xmlWriter->setAutoFormattingIndent(1);
176 xmlWriter->writeStartElement("MISCS");
177
178 query.first();
179 for (int i = 0 ; i < query.size() ; i++ ) {
180 xmlWriter->writeStartElement("MISC");
181 xmlWriter->writeTextElement("VERSION", "1");
182 xmlWriter->writeTextElement("NAME", query.value(1).toString());
183 xmlWriter->writeTextElement("TYPE", types[query.value(2).toInt()]);
184 xmlWriter->writeTextElement("AMOUNT_IS_WEIGHT", query.value(5).toInt() ? "TRUE":"FALSE");
185 xmlWriter->writeTextElement("USE", uses[query.value(3).toInt()]);
186 if (query.value(4).toDouble() > 0)
187 xmlWriter->writeTextElement("TIME", QString::number(query.value(4).toDouble(), 'f', 3));
188 if (query.value(10).toDouble() > 0)
189 xmlWriter->writeTextElement("COST", QString::number(query.value(10).toDouble(), 'f', 5));
190 xmlWriter->writeTextElement("ALWAYS_ON_STOCK", query.value(8).toInt() ? "TRUE":"FALSE");
191 if (query.value(7).toString().length())
192 xmlWriter->writeTextElement("NOTES", query.value(7).toString());
193 if (query.value(6).toString().length())
194 xmlWriter->writeTextElement("USE_FOR", query.value(6).toString());
195
196 xmlWriter->writeEndElement();
197 query.next();
198 }
199
200 xmlWriter->writeEndElement();
201 xmlWriter->writeEndDocument();
202 QMessageBox::information(this, tr("Save File"), tr("XML export ready"));
203
204 file.close();
205 }
206
207
150 void InventoryMiscs::on_quitButton_clicked() 208 void InventoryMiscs::on_quitButton_clicked()
151 { 209 {
152 emit firstWindow(); 210 emit firstWindow();
153 } 211 }
154 212

mercurial