Fix export increments and preview calculations.

Separate both types. First write increments then preview calculations.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2017-09-27 11:53:17 +03:00
parent 661e71bad0
commit 4caab9a479
2 changed files with 33 additions and 20 deletions

View File

@ -1499,30 +1499,42 @@ void MainWindow::ExportToCSVData(const QString &fileName, const DialogExportToCS
} }
const QMap<QString, QSharedPointer<VIncrement> > increments = pattern->DataIncrements(); const QMap<QString, QSharedPointer<VIncrement> > increments = pattern->DataIncrements();
QMap<QString, QSharedPointer<VIncrement> >::const_iterator i;
QMap<quint32, QString> map;
//Sorting QHash by id
for (i = increments.constBegin(); i != increments.constEnd(); ++i)
{
QSharedPointer<VIncrement> incr = i.value();
map.insert(incr->getIndex(), i.key());
}
qint32 currentRow = -1; qint32 currentRow = -1;
QMapIterator<quint32, QString> iMap(map);
while (iMap.hasNext()) auto SavePreviewCalculation = [&currentRow, &csv, increments](bool save)
{ {
iMap.next(); QMap<QString, QSharedPointer<VIncrement> >::const_iterator i;
QSharedPointer<VIncrement> incr = increments.value(iMap.value()); QMap<quint32, QString> map;
currentRow++; //Sorting QHash by id
for (i = increments.constBegin(); i != increments.constEnd(); ++i)
{
const QSharedPointer<VIncrement> incr = i.value();
if (incr->IsPreviewCalculation() == save)
{
map.insert(incr->getIndex(), i.key());
}
}
csv.insertRow(currentRow); QMapIterator<quint32, QString> iMap(map);
csv.setText(currentRow, 0, incr->GetName()); // name while (iMap.hasNext())
csv.setText(currentRow, 1, qApp->LocaleToString(*incr->GetValue())); // calculated value {
iMap.next();
QSharedPointer<VIncrement> incr = increments.value(iMap.value());
currentRow++;
QString formula = VTranslateVars::TryFormulaToUser(incr->GetFormula(), qApp->Settings()->GetOsSeparator()); csv.insertRow(currentRow);
csv.setText(currentRow, 2, formula); // formula csv.setText(currentRow, 0, incr->GetName()); // name
} csv.setText(currentRow, 1, qApp->LocaleToString(*incr->GetValue())); // calculated value
QString formula = VTranslateVars::TryFormulaToUser(incr->GetFormula(),
qApp->Settings()->GetOsSeparator());
csv.setText(currentRow, 2, formula); // formula
}
};
SavePreviewCalculation(false);
SavePreviewCalculation(true);
csv.toCSV(fileName, dialog.WithHeader(), dialog.Separator(), QTextCodec::codecForMib(dialog.SelectedMib())); csv.toCSV(fileName, dialog.WithHeader(), dialog.Separator(), QTextCodec::codecForMib(dialog.SelectedMib()));
} }

View File

@ -80,7 +80,8 @@ VIncrement::~VIncrement()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/** /**
* @brief getIndex return index of row * @brief getIndex return index of row. Row index for increments and preview calucalations is unique. Check type before
* using.
* @return index * @return index
*/ */
quint32 VIncrement::getIndex() const quint32 VIncrement::getIndex() const