New feature Export to individual measurements.

This commit is contained in:
Roman Telezhynskyi 2020-10-05 11:45:16 +03:00
parent 7c66482b67
commit f96fd45a90
4 changed files with 126 additions and 10 deletions

View File

@ -2110,6 +2110,85 @@ void TMainWindow::FullCircumferenceChanged(bool checked)
InitDimensionControls(); InitDimensionControls();
} }
//---------------------------------------------------------------------------------------------------------------------
void TMainWindow::ExportToIndividual()
{
QString dir;
if (curFile.isEmpty())
{
dir = qApp->TapeSettings()->GetPathIndividualMeasurements();
}
else
{
dir = QFileInfo(curFile).absolutePath();
}
bool usedNotExistedDir = false;
QDir directory(dir);
if (not directory.exists())
{
usedNotExistedDir = directory.mkpath(QChar('.'));
}
QString filters = tr("Individual measurements") + QStringLiteral(" (*.vit)");
QString fName = tr("measurements.vit");
QString fileName = QFileDialog::getSaveFileName(this, tr("Export to individual"), dir + QChar('/') + fName,
filters);
auto RemoveTempDir = qScopeGuard([usedNotExistedDir, dir]()
{
if (usedNotExistedDir)
{
QDir(dir).rmpath(QChar('.'));
}
});
if (fileName.isEmpty())
{
return;
}
QString suffix = QStringLiteral("vit");
QFileInfo f( fileName );
if (f.suffix().isEmpty() && f.suffix() != suffix)
{
fileName += QChar('.') + suffix;
}
QScopedPointer<VContainer> tmpData(new VContainer(qApp->TrVars(), &mUnit, VContainer::UniqueNamespace()));
VMeasurements individualMeasurements(mUnit, tmpData.data());
const QMap<int, QSharedPointer<VMeasurement> > orderedTable = OrderedMeasurments();
QMap<int, QSharedPointer<VMeasurement> >::const_iterator iMap;
for (iMap = orderedTable.constBegin(); iMap != orderedTable.constEnd(); ++iMap)
{
const QSharedPointer<VMeasurement> &meash = iMap.value();
individualMeasurements.AddEmpty(meash->GetName());
individualMeasurements.SetMValue(meash->GetName(), QString::number(*meash->GetValue()));
individualMeasurements.SetMSpecialUnits(meash->GetName(), meash->IsSpecialUnits());
if (meash->IsCustom())
{
individualMeasurements.SetMDescription(meash->GetName(), meash->GetDescription());
individualMeasurements.SetMFullName(meash->GetName(), meash->GetGuiText());
}
}
QString error;
const bool result = individualMeasurements.SaveDocument(fileName, error);
if (not result)
{
QMessageBox messageBox;
messageBox.setIcon(QMessageBox::Warning);
messageBox.setInformativeText(tr("Could not save the file"));
messageBox.setDefaultButton(QMessageBox::Ok);
messageBox.setDetailedText(error);
messageBox.setStandardButtons(QMessageBox::Ok);
messageBox.exec();
return;
}
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void TMainWindow::SetupMenu() void TMainWindow::SetupMenu()
{ {
@ -2387,6 +2466,10 @@ void TMainWindow::InitMenu()
actionFullCircumference->setChecked(m->IsFullCircumference()); actionFullCircumference->setChecked(m->IsFullCircumference());
ui->menuMeasurements->addAction(actionFullCircumference); ui->menuMeasurements->addAction(actionFullCircumference);
connect(actionFullCircumference, &QAction::triggered, this, &TMainWindow::FullCircumferenceChanged); connect(actionFullCircumference, &QAction::triggered, this, &TMainWindow::FullCircumferenceChanged);
ui->actionExportToIndividual->setVisible(true);
ui->actionExportToIndividual->setEnabled(true);
connect(ui->actionExportToIndividual, &QAction::triggered, this, &TMainWindow::ExportToIndividual);
} }
} }
@ -2778,15 +2861,7 @@ void TMainWindow::RefreshTable(bool freshCall)
ShowUnits(); ShowUnits();
const QMap<QString, QSharedPointer<VMeasurement> > table = data->DataMeasurements(); const QMap<int, QSharedPointer<VMeasurement> > orderedTable = OrderedMeasurments();
QMap<int, QSharedPointer<VMeasurement> > orderedTable;
QMap<QString, QSharedPointer<VMeasurement> >::const_iterator iterMap;
for (iterMap = table.constBegin(); iterMap != table.constEnd(); ++iterMap)
{
const QSharedPointer<VMeasurement> &meash = iterMap.value();
orderedTable.insert(meash->Index(), meash);
}
qint32 currentRow = -1; qint32 currentRow = -1;
QMap<int, QSharedPointer<VMeasurement> >::const_iterator iMap; QMap<int, QSharedPointer<VMeasurement> >::const_iterator iMap;
ui->tableWidget->setRowCount ( orderedTable.size() ); ui->tableWidget->setRowCount ( orderedTable.size() );
@ -3981,6 +4056,21 @@ QVector<int> TMainWindow::DimensionRestrictedValues(int index, const Measurement
return QVector<int>(); return QVector<int>();
} }
//---------------------------------------------------------------------------------------------------------------------
QMap<int, QSharedPointer<VMeasurement> > TMainWindow::OrderedMeasurments() const
{
const QMap<QString, QSharedPointer<VMeasurement> > table = data->DataMeasurements();
QMap<int, QSharedPointer<VMeasurement> > orderedTable;
QMap<QString, QSharedPointer<VMeasurement> >::const_iterator iterMap;
for (iterMap = table.constBegin(); iterMap != table.constEnd(); ++iterMap)
{
const QSharedPointer<VMeasurement> &meash = iterMap.value();
orderedTable.insert(meash->Index(), meash);
}
return orderedTable;
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void TMainWindow::SetDecimals() void TMainWindow::SetDecimals()
{ {

View File

@ -44,6 +44,7 @@ namespace Ui
class QLabel; class QLabel;
class QxtCsvModel; class QxtCsvModel;
class VMeasurement;
class TMainWindow : public VAbstractMainWindow class TMainWindow : public VAbstractMainWindow
{ {
@ -136,6 +137,8 @@ private slots:
void FullCircumferenceChanged(bool checked); void FullCircumferenceChanged(bool checked);
void ExportToIndividual();
private: private:
Q_DISABLE_COPY(TMainWindow) Q_DISABLE_COPY(TMainWindow)
Ui::TMainWindow *ui; Ui::TMainWindow *ui;
@ -243,6 +246,8 @@ private:
void SetCurrentDimensionValues(); void SetCurrentDimensionValues();
QVector<int> DimensionRestrictedValues(int index, const MeasurementDimension_p &dimension); QVector<int> DimensionRestrictedValues(int index, const MeasurementDimension_p &dimension);
QMap<int, QSharedPointer<VMeasurement> > OrderedMeasurments() const;
}; };
#endif // TMAINWINDOW_H #endif // TMAINWINDOW_H

View File

@ -963,6 +963,7 @@
<addaction name="actionSaveAs"/> <addaction name="actionSaveAs"/>
<addaction name="actionExportToCSV"/> <addaction name="actionExportToCSV"/>
<addaction name="actionImportFromCSV"/> <addaction name="actionImportFromCSV"/>
<addaction name="actionExportToIndividual"/>
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="actionReadOnly"/> <addaction name="actionReadOnly"/>
<addaction name="separator"/> <addaction name="separator"/>
@ -1332,6 +1333,26 @@
<enum>QAction::NoRole</enum> <enum>QAction::NoRole</enum>
</property> </property>
</action> </action>
<action name="actionExportToIndividual">
<property name="checkable">
<bool>false</bool>
</property>
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Export to individual</string>
</property>
<property name="toolTip">
<string>Export to individual measurements</string>
</property>
<property name="visible">
<bool>false</bool>
</property>
<property name="menuRole">
<enum>QAction::NoRole</enum>
</property>
</action>
</widget> </widget>
<layoutdefault spacing="6" margin="11"/> <layoutdefault spacing="6" margin="11"/>
<customwidgets> <customwidgets>