Export Final measurements to CSV.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2017-09-27 14:47:05 +03:00
parent 257fb2f913
commit ac96ce6b84
6 changed files with 104 additions and 4 deletions

View File

@ -2837,6 +2837,7 @@ void MainWindow::Clear()
ui->actionHistory->setEnabled(false); ui->actionHistory->setEnabled(false);
ui->actionTable->setEnabled(false); ui->actionTable->setEnabled(false);
ui->actionExportIncrementsToCSV->setEnabled(false); ui->actionExportIncrementsToCSV->setEnabled(false);
ui->actionExportFinalMeasurementsToCSV->setEnabled(false);
ui->actionFinalMeasurements->setEnabled(false); ui->actionFinalMeasurements->setEnabled(false);
ui->actionLast_tool->setEnabled(false); ui->actionLast_tool->setEnabled(false);
ui->actionShowCurveDetails->setEnabled(false); ui->actionShowCurveDetails->setEnabled(false);
@ -3084,6 +3085,7 @@ void MainWindow::SetEnableWidgets(bool enable)
ui->actionLayout->setEnabled(enable); ui->actionLayout->setEnabled(enable);
ui->actionTable->setEnabled(enable && drawStage); ui->actionTable->setEnabled(enable && drawStage);
ui->actionExportIncrementsToCSV->setEnabled(enable); ui->actionExportIncrementsToCSV->setEnabled(enable);
ui->actionExportFinalMeasurementsToCSV->setEnabled(enable);
ui->actionFinalMeasurements->setEnabled(enable); ui->actionFinalMeasurements->setEnabled(enable);
ui->actionZoomFitBest->setEnabled(enable); ui->actionZoomFitBest->setEnabled(enable);
ui->actionZoomFitBestCurrent->setEnabled(enable && drawStage); ui->actionZoomFitBestCurrent->setEnabled(enable && drawStage);
@ -3978,6 +3980,7 @@ void MainWindow::CreateActions()
connect(ui->actionOpen, &QAction::triggered, this, &MainWindow::Open); connect(ui->actionOpen, &QAction::triggered, this, &MainWindow::Open);
connect(ui->actionNew, &QAction::triggered, this, &MainWindow::New); connect(ui->actionNew, &QAction::triggered, this, &MainWindow::New);
connect(ui->actionExportIncrementsToCSV, &QAction::triggered, this, &MainWindow::ExportDataToCSV); connect(ui->actionExportIncrementsToCSV, &QAction::triggered, this, &MainWindow::ExportDataToCSV);
connect(ui->actionExportFinalMeasurementsToCSV, &QAction::triggered, this, &MainWindow::ExportFMeasurementsToCSV);
connect(ui->actionTable, &QAction::triggered, this, [this](bool checked) connect(ui->actionTable, &QAction::triggered, this, [this](bool checked)
{ {

View File

@ -1709,6 +1709,7 @@
<addaction name="actionExportIncrementsToCSV"/> <addaction name="actionExportIncrementsToCSV"/>
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="actionFinalMeasurements"/> <addaction name="actionFinalMeasurements"/>
<addaction name="actionExportFinalMeasurementsToCSV"/>
</widget> </widget>
<widget class="QMenu" name="menuWindow"> <widget class="QMenu" name="menuWindow">
<property name="title"> <property name="title">
@ -2693,6 +2694,14 @@
<string>Final measurements</string> <string>Final measurements</string>
</property> </property>
</action> </action>
<action name="actionExportFinalMeasurementsToCSV">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Export Final Measurements to CSV</string>
</property>
</action>
</widget> </widget>
<layoutdefault spacing="6" margin="11"/> <layoutdefault spacing="6" margin="11"/>
<customwidgets> <customwidgets>
@ -2703,8 +2712,8 @@
</customwidget> </customwidget>
</customwidgets> </customwidgets>
<resources> <resources>
<include location="../../libs/vmisc/share/resources/icon.qrc"/>
<include location="share/resources/toolicon.qrc"/> <include location="share/resources/toolicon.qrc"/>
<include location="../../libs/vmisc/share/resources/icon.qrc"/>
</resources> </resources>
<connections/> <connections/>
</ui> </ui>

View File

@ -33,6 +33,8 @@
#include "../vdxf/vdxfpaintdevice.h" #include "../vdxf/vdxfpaintdevice.h"
#include "dialogs/dialoglayoutsettings.h" #include "dialogs/dialoglayoutsettings.h"
#include "../vwidgets/vmaingraphicsscene.h" #include "../vwidgets/vmaingraphicsscene.h"
#include "../vmisc/dialogs/dialogexporttocsv.h"
#include "../vmisc/qxtcsvmodel.h"
#include "../vlayout/vlayoutgenerator.h" #include "../vlayout/vlayoutgenerator.h"
#include "dialogs/dialoglayoutprogress.h" #include "dialogs/dialoglayoutprogress.h"
#include "dialogs/dialogsavelayout.h" #include "dialogs/dialogsavelayout.h"
@ -41,6 +43,7 @@
#include "../vpatterndb/floatItemData/vpatternlabeldata.h" #include "../vpatterndb/floatItemData/vpatternlabeldata.h"
#include "../vpatterndb/floatItemData/vgrainlinedata.h" #include "../vpatterndb/floatItemData/vgrainlinedata.h"
#include "../vpatterndb/measurements.h" #include "../vpatterndb/measurements.h"
#include "../vpatterndb/calculator.h"
#include "../vtools/tools/vabstracttool.h" #include "../vtools/tools/vabstracttool.h"
#include "../vtools/tools/vtoolseamallowance.h" #include "../vtools/tools/vtoolseamallowance.h"
@ -224,6 +227,31 @@ void MainWindowsNoGUI::ErrorConsoleMode(const LayoutErrors &state)
qApp->exit(V_EX_DATAERR); qApp->exit(V_EX_DATAERR);
} }
//---------------------------------------------------------------------------------------------------------------------
void MainWindowsNoGUI::ExportFMeasurementsToCSV()
{
QString fileName = CSVFilePath();
if (fileName.isEmpty())
{
return;
}
DialogExportToCSV dialog(this);
dialog.SetWithHeader(qApp->Settings()->GetCSVWithHeader());
dialog.SetSelectedMib(qApp->Settings()->GetCSVCodec());
dialog.SetSeparator(qApp->Settings()->GetCSVSeparator());
if (dialog.exec() == QDialog::Accepted)
{
ExportFMeasurementsToCSVData(fileName, dialog.IsWithHeader(), dialog.GetSelectedMib(), dialog.GetSeparator());
qApp->Settings()->SetCSVSeparator(dialog.GetSeparator());
qApp->Settings()->SetCSVCodec(dialog.GetSelectedMib());
qApp->Settings()->SetCSVWithHeader(dialog.IsWithHeader());
}
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void MainWindowsNoGUI::ExportData(const QVector<VLayoutPiece> &listDetails, const DialogSaveLayout &dialog) void MainWindowsNoGUI::ExportData(const QVector<VLayoutPiece> &listDetails, const DialogSaveLayout &dialog)
{ {
@ -1543,6 +1571,59 @@ void MainWindowsNoGUI::SetSizeHeightForIndividualM() const
emit doc->UpdatePatternLabel(); emit doc->UpdatePatternLabel();
} }
//---------------------------------------------------------------------------------------------------------------------
void MainWindowsNoGUI::ExportFMeasurementsToCSVData(const QString &fileName, bool withHeader, int mib,
const QChar &separator) const
{
QxtCsvModel csv;
csv.insertColumn(0);
csv.insertColumn(1);
if (withHeader)
{
csv.setHeaderText(0, tr("Name"));
csv.setHeaderText(1, tr("Value"));
}
const QVector<VFinalMeasurement> measurements = doc->GetFinalMeasurements();
const VContainer completeData = doc->GetCompleteData();
for (int i=0; i < measurements.size(); ++i)
{
const VFinalMeasurement &m = measurements.at(i);
csv.insertRow(i);
csv.setText(i, 0, m.name); // name
qreal result = 0;
if (not m.formula.isEmpty())
{
try
{
QString f = m.formula;
// Replace line return character with spaces for calc if exist
f.replace("\n", " ");
QScopedPointer<Calculator> cal(new Calculator());
result = cal->EvalFormula(completeData.DataVariables(), f);
if (qIsInf(result) || qIsNaN(result))
{
result = 0;
}
}
catch (qmu::QmuParserError &)
{
result = 0;
}
}
csv.setText(i, 1, qApp->LocaleToString(result)); // value
}
csv.toCSV(fileName, withHeader, separator, QTextCodec::codecForMib(mib));
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
int MainWindowsNoGUI::ContinueIfLayoutStale() int MainWindowsNoGUI::ContinueIfLayoutStale()
{ {

View File

@ -56,6 +56,8 @@ public slots:
void PrintOrigin(); void PrintOrigin();
void PrintTiled(); void PrintTiled();
void RefreshDetailsLabel(); void RefreshDetailsLabel();
protected slots:
void ExportFMeasurementsToCSV();
protected: protected:
QVector<VLayoutPiece> listDetails; QVector<VLayoutPiece> listDetails;
@ -100,6 +102,9 @@ protected:
int ContinueIfLayoutStale(); int ContinueIfLayoutStale();
QString FileName() const; QString FileName() const;
void SetSizeHeightForIndividualM() const; void SetSizeHeightForIndividualM() const;
void ExportFMeasurementsToCSVData(const QString &fileName,
bool withHeader, int mib, const QChar &separator) const;
private slots: private slots:
void PrintPages (QPrinter *printer); void PrintPages (QPrinter *printer);
void ErrorConsoleMode(const LayoutErrors &state); void ErrorConsoleMode(const LayoutErrors &state);

View File

@ -30,6 +30,7 @@
#include "../vpropertyexplorer/checkablemessagebox.h" #include "../vpropertyexplorer/checkablemessagebox.h"
#include "../vmisc/vabstractapplication.h" #include "../vmisc/vabstractapplication.h"
#include "dialogs/dialogexporttocsv.h" #include "dialogs/dialogexporttocsv.h"
#include "../ifc/xml/vabstractpattern.h"
#include <QStyle> #include <QStyle>
#include <QToolBar> #include <QToolBar>

View File

@ -35,7 +35,7 @@
#include <QObject> #include <QObject>
#include <QString> #include <QString>
class DialogExportToCSV; class VFinalMeasurement;
class VAbstractMainWindow : public QMainWindow class VAbstractMainWindow : public QMainWindow
{ {
@ -58,11 +58,12 @@ protected:
bool ContinueFormatRewrite(const QString &currentFormatVersion, const QString &maxFormatVersion); bool ContinueFormatRewrite(const QString &currentFormatVersion, const QString &maxFormatVersion);
void ToolBarStyle(QToolBar *bar); void ToolBarStyle(QToolBar *bar);
QString CSVFilePath();
virtual void ExportToCSVData(const QString &fileName, bool withHeader, int mib, const QChar &separator)=0; virtual void ExportToCSVData(const QString &fileName, bool withHeader, int mib, const QChar &separator)=0;
private: private:
Q_DISABLE_COPY(VAbstractMainWindow) Q_DISABLE_COPY(VAbstractMainWindow)
QString CSVFilePath();
}; };
#endif // VABSTRACTMAINWINDOW_H #endif // VABSTRACTMAINWINDOW_H