Resolved issue #682. New feature. Export increments to Excel .csv.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2017-05-12 15:09:19 +03:00
parent ac51dab6c7
commit 7225481091
18 changed files with 291 additions and 197 deletions

View File

@ -1,3 +1,6 @@
# Version 0.6.0
- [#682] New feature. Export increments to Excel .csv.
# Version 0.5.0 May 9, 2017 # Version 0.5.0 May 9, 2017
- [#581] User can now filter input lists by keyword in function wizard. - [#581] User can now filter input lists by keyword in function wizard.
- [#24] User can now add labels with different information on the detail - [#24] User can now add labels with different information on the detail

View File

@ -8,7 +8,6 @@ SOURCES += \
$$PWD/dialogs/dialogabouttape.cpp \ $$PWD/dialogs/dialogabouttape.cpp \
$$PWD/dialogs/dialognewmeasurements.cpp \ $$PWD/dialogs/dialognewmeasurements.cpp \
$$PWD/dialogs/dialogmdatabase.cpp \ $$PWD/dialogs/dialogmdatabase.cpp \
$$PWD/dialogs/dialogexporttocsv.cpp \
$$PWD/vlitepattern.cpp \ $$PWD/vlitepattern.cpp \
$$PWD/dialogs/dialogtapepreferences.cpp \ $$PWD/dialogs/dialogtapepreferences.cpp \
$$PWD/dialogs/configpages/tapepreferencesconfigurationpage.cpp \ $$PWD/dialogs/configpages/tapepreferencesconfigurationpage.cpp \
@ -24,7 +23,6 @@ HEADERS += \
$$PWD/dialogs/dialognewmeasurements.h \ $$PWD/dialogs/dialognewmeasurements.h \
$$PWD/dialogs/dialogmdatabase.h \ $$PWD/dialogs/dialogmdatabase.h \
$$PWD/version.h \ $$PWD/version.h \
$$PWD/dialogs/dialogexporttocsv.h \
$$PWD/vlitepattern.h \ $$PWD/vlitepattern.h \
$$PWD/dialogs/dialogtapepreferences.h \ $$PWD/dialogs/dialogtapepreferences.h \
$$PWD/dialogs/configpages/tapepreferencesconfigurationpage.h \ $$PWD/dialogs/configpages/tapepreferencesconfigurationpage.h \
@ -35,7 +33,6 @@ FORMS += \
$$PWD/dialogs/dialogabouttape.ui \ $$PWD/dialogs/dialogabouttape.ui \
$$PWD/dialogs/dialognewmeasurements.ui \ $$PWD/dialogs/dialognewmeasurements.ui \
$$PWD/dialogs/dialogmdatabase.ui \ $$PWD/dialogs/dialogmdatabase.ui \
$$PWD/dialogs/dialogexporttocsv.ui \
$$PWD/dialogs/dialogtapepreferences.ui \ $$PWD/dialogs/dialogtapepreferences.ui \
$$PWD/dialogs/configpages/tapepreferencesconfigurationpage.ui \ $$PWD/dialogs/configpages/tapepreferencesconfigurationpage.ui \
$$PWD/dialogs/configpages/tapepreferencespathpage.ui $$PWD/dialogs/configpages/tapepreferencespathpage.ui

View File

@ -658,6 +658,55 @@ bool TMainWindow::eventFilter(QObject *object, QEvent *event)
return false;// pass the event to the widget return false;// pass the event to the widget
} }
//---------------------------------------------------------------------------------------------------------------------
void TMainWindow::ExportToCSVData(const QString &fileName, const DialogExportToCSV &dialog)
{
QxtCsvModel csv;
const int columns = ui->tableWidget->columnCount();
{
int colCount = 0;
for (int column = 0; column < columns; ++column)
{
if (not ui->tableWidget->isColumnHidden(column))
{
csv.insertColumn(colCount++);
}
}
}
if (dialog.WithHeader())
{
int colCount = 0;
for (int column = 0; column < columns; ++column)
{
if (not ui->tableWidget->isColumnHidden(column))
{
QTableWidgetItem *header = ui->tableWidget->horizontalHeaderItem(colCount);
csv.setHeaderText(colCount, header->text());
++colCount;
}
}
}
const int rows = ui->tableWidget->rowCount();
for (int row = 0; row < rows; ++row)
{
csv.insertRow(row);
int colCount = 0;
for (int column = 0; column < columns; ++column)
{
if (not ui->tableWidget->isColumnHidden(column))
{
QTableWidgetItem *item = ui->tableWidget->item(row, column);
csv.setText(row, colCount, item->text());
++colCount;
}
}
}
csv.toCSV(fileName, dialog.WithHeader(), dialog.Separator(), QTextCodec::codecForMib(dialog.SelectedMib()));
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
bool TMainWindow::FileSave() bool TMainWindow::FileSave()
{ {
@ -875,80 +924,6 @@ bool TMainWindow::FileSaveAs()
return true; return true;
} }
//---------------------------------------------------------------------------------------------------------------------
void TMainWindow::ExportToCSV()
{
const QString filters = tr("Comma-Separated Values") + QLatin1String(" (*.cvs)");
const QString suffix("csv");
const QString path = QDir::homePath() + QLatin1String("/") + tr("measurements") + QLatin1String(".") + suffix;
QString fileName = QFileDialog::getSaveFileName(this, tr("Export to CSV"), path, filters);
if (fileName.isEmpty())
{
return;
}
QFileInfo f( fileName );
if (f.suffix().isEmpty() && f.suffix() != suffix)
{
fileName += QLatin1String(".") + suffix;
}
DialogExportToCSV dialog(this);
if (dialog.exec() == QDialog::Accepted)
{
QxtCsvModel csv;
const int columns = ui->tableWidget->columnCount();
{
int colCount = 0;
for (int column = 0; column < columns; ++column)
{
if (not ui->tableWidget->isColumnHidden(column))
{
csv.insertColumn(colCount++);
}
}
}
if (dialog.WithHeader())
{
int colCount = 0;
for (int column = 0; column < columns; ++column)
{
if (not ui->tableWidget->isColumnHidden(column))
{
QTableWidgetItem *header = ui->tableWidget->horizontalHeaderItem(colCount);
csv.setHeaderText(colCount, header->text());
++colCount;
}
}
}
const int rows = ui->tableWidget->rowCount();
for (int row = 0; row < rows; ++row)
{
csv.insertRow(row);
int colCount = 0;
for (int column = 0; column < columns; ++column)
{
if (not ui->tableWidget->isColumnHidden(column))
{
QTableWidgetItem *item = ui->tableWidget->item(row, column);
csv.setText(row, colCount, item->text());
++colCount;
}
}
}
csv.toCSV(fileName, dialog.WithHeader(), dialog.Separator(), QTextCodec::codecForMib(dialog.SelectedMib()));
qApp->TapeSettings()->SetCSVSeparator(dialog.Separator());
qApp->TapeSettings()->SetCSVCodec(dialog.SelectedMib());
qApp->TapeSettings()->SetCSVWithHeader(dialog.WithHeader());
}
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void TMainWindow::AboutToShowWindowMenu() void TMainWindow::AboutToShowWindowMenu()
{ {

View File

@ -70,6 +70,7 @@ protected:
virtual void changeEvent(QEvent* event) Q_DECL_OVERRIDE; virtual void changeEvent(QEvent* event) Q_DECL_OVERRIDE;
virtual void showEvent(QShowEvent *event) Q_DECL_OVERRIDE; virtual void showEvent(QShowEvent *event) Q_DECL_OVERRIDE;
virtual bool eventFilter(QObject *object, QEvent *event) Q_DECL_OVERRIDE; virtual bool eventFilter(QObject *object, QEvent *event) Q_DECL_OVERRIDE;
virtual void ExportToCSVData(const QString &fileName, const DialogExportToCSV &dialog) Q_DECL_FINAL;
private slots: private slots:
void FileNew(); void FileNew();
@ -82,7 +83,6 @@ private slots:
bool FileSave(); bool FileSave();
bool FileSaveAs(); bool FileSaveAs();
void ExportToCSV();
void AboutToShowWindowMenu(); void AboutToShowWindowMenu();
void ShowWindow() const; void ShowWindow() const;

View File

@ -39,6 +39,8 @@
#include "../vmisc/undoevent.h" #include "../vmisc/undoevent.h"
#include "../vmisc/vsettings.h" #include "../vmisc/vsettings.h"
#include "../vmisc/def.h" #include "../vmisc/def.h"
#include "../vmisc/qxtcsvmodel.h"
#include "../vmisc/dialogs/dialogexporttocsv.h"
#include "undocommands/renamepp.h" #include "undocommands/renamepp.h"
#include "core/vtooloptionspropertybrowser.h" #include "core/vtooloptionspropertybrowser.h"
#include "options.h" #include "options.h"
@ -60,6 +62,7 @@
#include "../vtools/undocommands/addgroup.h" #include "../vtools/undocommands/addgroup.h"
#include "dialogs/vwidgetdetails.h" #include "dialogs/vwidgetdetails.h"
#include "../vpatterndb/vpiecepath.h" #include "../vpatterndb/vpiecepath.h"
#include "../qmuparser/qmuparsererror.h"
#include <QInputDialog> #include <QInputDialog>
#include <QtDebug> #include <QtDebug>
@ -80,6 +83,7 @@
#include <thread> #include <thread>
#include <QFileSystemWatcher> #include <QFileSystemWatcher>
#include <QComboBox> #include <QComboBox>
#include <QTextCodec>
#if defined(Q_OS_MAC) #if defined(Q_OS_MAC)
#include <QMimeData> #include <QMimeData>
@ -1417,6 +1421,61 @@ void MainWindow::PrepareSceneList()
} }
} }
//---------------------------------------------------------------------------------------------------------------------
void MainWindow::ExportToCSVData(const QString &fileName, const DialogExportToCSV &dialog)
{
QxtCsvModel csv;
csv.insertColumn(0);
csv.insertColumn(1);
csv.insertColumn(2);
if (dialog.WithHeader())
{
csv.setHeaderText(0, tr("Name"));
csv.setHeaderText(1, tr("The calculated value"));
csv.setHeaderText(2, tr("Formula"));
}
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;
QMapIterator<quint32, QString> iMap(map);
while (iMap.hasNext())
{
iMap.next();
QSharedPointer<VIncrement> incr = increments.value(iMap.value());
currentRow++;
csv.insertRow(currentRow);
csv.setText(currentRow, 0, incr->GetName()); // name
csv.setText(currentRow, 1, qApp->LocaleToString(*incr->GetValue())); // calculated value
QString formula;
try
{
formula = qApp->TrVars()->FormulaToUser(incr->GetFormula(), qApp->Settings()->GetOsSeparator());
}
catch (qmu::QmuParserError &e)
{
Q_UNUSED(e)
formula = incr->GetFormula();
}
csv.setText(currentRow, 2, formula); // formula
}
csv.toCSV(fileName, dialog.WithHeader(), dialog.Separator(), QTextCodec::codecForMib(dialog.SelectedMib()));
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void MainWindow::LoadIndividual() void MainWindow::LoadIndividual()
{ {
@ -3821,6 +3880,7 @@ void MainWindow::CreateActions()
connect(ui->actionSave, &QAction::triggered, this, &MainWindow::Save); connect(ui->actionSave, &QAction::triggered, this, &MainWindow::Save);
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::ExportToCSV);
connect(ui->actionTable, &QAction::triggered, RECEIVER(this)[this](bool checked) connect(ui->actionTable, &QAction::triggered, RECEIVER(this)[this](bool checked)
{ {

View File

@ -102,6 +102,7 @@ protected:
virtual void customEvent(QEvent * event) Q_DECL_OVERRIDE; virtual void customEvent(QEvent * event) Q_DECL_OVERRIDE;
virtual void CleanLayout() Q_DECL_OVERRIDE; virtual void CleanLayout() Q_DECL_OVERRIDE;
virtual void PrepareSceneList() Q_DECL_OVERRIDE; virtual void PrepareSceneList() Q_DECL_OVERRIDE;
virtual void ExportToCSVData(const QString &fileName, const DialogExportToCSV &dialog) Q_DECL_FINAL;
private slots: private slots:
void MouseMove(const QPointF &scenePos); void MouseMove(const QPointF &scenePos);
void Clear(); void Clear();

View File

@ -55,7 +55,7 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>100</width> <width>127</width>
<height>358</height> <height>358</height>
</rect> </rect>
</property> </property>
@ -427,7 +427,7 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>100</width> <width>127</width>
<height>110</height> <height>110</height>
</rect> </rect>
</property> </property>
@ -536,7 +536,7 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>100</width> <width>127</width>
<height>248</height> <height>248</height>
</rect> </rect>
</property> </property>
@ -798,7 +798,7 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>100</width> <width>127</width>
<height>248</height> <height>248</height>
</rect> </rect>
</property> </property>
@ -1146,8 +1146,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>100</width> <width>140</width>
<height>196</height> <height>326</height>
</rect> </rect>
</property> </property>
<attribute name="icon"> <attribute name="icon">
@ -1324,7 +1324,7 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>100</width> <width>127</width>
<height>196</height> <height>196</height>
</rect> </rect>
</property> </property>
@ -1511,8 +1511,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>100</width> <width>140</width>
<height>58</height> <height>326</height>
</rect> </rect>
</property> </property>
<attribute name="icon"> <attribute name="icon">
@ -1679,6 +1679,7 @@
<addaction name="actionLoadStandard"/> <addaction name="actionLoadStandard"/>
<addaction name="actionSyncMeasurements"/> <addaction name="actionSyncMeasurements"/>
<addaction name="actionTable"/> <addaction name="actionTable"/>
<addaction name="actionExportIncrementsToCSV"/>
</widget> </widget>
<widget class="QMenu" name="menuWindow"> <widget class="QMenu" name="menuWindow">
<property name="title"> <property name="title">
@ -2640,6 +2641,11 @@
<enum>QAction::NoRole</enum> <enum>QAction::NoRole</enum>
</property> </property>
</action> </action>
<action name="actionExportIncrementsToCSV">
<property name="text">
<string>Export increments to CSV</string>
</property>
</action>
</widget> </widget>
<layoutdefault spacing="6" margin="11"/> <layoutdefault spacing="6" margin="11"/>
<customwidgets> <customwidgets>
@ -2650,8 +2656,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

@ -29,8 +29,8 @@
#include "dialogexporttocsv.h" #include "dialogexporttocsv.h"
#include "ui_dialogexporttocsv.h" #include "ui_dialogexporttocsv.h"
#include "../vmisc/vtapesettings.h" #include "../vmisc/vcommonsettings.h"
#include "../mapplication.h" #include "../vabstractapplication.h"
#include <QPushButton> #include <QPushButton>
#include <QShowEvent> #include <QShowEvent>
@ -44,25 +44,25 @@ DialogExportToCSV::DialogExportToCSV(QWidget *parent)
{ {
ui->setupUi(this); ui->setupUi(this);
ui->checkBoxWithHeader->setChecked(qApp->TapeSettings()->GetCSVWithHeader()); ui->checkBoxWithHeader->setChecked(qApp->Settings()->GetCSVWithHeader());
foreach (int mib, QTextCodec::availableMibs()) foreach (int mib, QTextCodec::availableMibs())
{ {
ui->comboBoxCodec->addItem(QTextCodec::codecForMib(mib)->name(), mib); ui->comboBoxCodec->addItem(QTextCodec::codecForMib(mib)->name(), mib);
} }
ui->comboBoxCodec->setCurrentIndex(ui->comboBoxCodec->findData(qApp->TapeSettings()->GetCSVCodec())); ui->comboBoxCodec->setCurrentIndex(ui->comboBoxCodec->findData(qApp->Settings()->GetCSVCodec()));
SetSeparator(qApp->TapeSettings()->GetCSVSeparator()); SetSeparator(qApp->Settings()->GetCSVSeparator());
QPushButton *bDefaults = ui->buttonBox->button(QDialogButtonBox::RestoreDefaults); QPushButton *bDefaults = ui->buttonBox->button(QDialogButtonBox::RestoreDefaults);
SCASSERT(bDefaults != nullptr) SCASSERT(bDefaults != nullptr)
connect(bDefaults, &QPushButton::clicked, RECEIVER(this)[this]() connect(bDefaults, &QPushButton::clicked, this, [this]()
{ {
ui->checkBoxWithHeader->setChecked(qApp->TapeSettings()->GetDefCSVWithHeader()); ui->checkBoxWithHeader->setChecked(qApp->Settings()->GetDefCSVWithHeader());
ui->comboBoxCodec->setCurrentIndex(ui->comboBoxCodec->findData(qApp->TapeSettings()->GetDefCSVCodec())); ui->comboBoxCodec->setCurrentIndex(ui->comboBoxCodec->findData(qApp->Settings()->GetDefCSVCodec()));
SetSeparator(qApp->TapeSettings()->GetDefCSVSeparator()); SetSeparator(qApp->Settings()->GetDefCSVSeparator());
}); });
} }

View File

@ -38,6 +38,7 @@
#include <QStringDataPtr> #include <QStringDataPtr>
#include <QVariant> #include <QVariant>
#include <QtDebug> #include <QtDebug>
#include <QTextCodec>
#include "../vmisc/def.h" #include "../vmisc/def.h"
#include "../vmisc/vmath.h" #include "../vmisc/vmath.h"
@ -72,6 +73,10 @@ const QString settingLatestSkippedVersion = QStringLiteral("lastestSkippedVers
const QString settingDateOfLastRemind = QStringLiteral("dateOfLastRemind"); const QString settingDateOfLastRemind = QStringLiteral("dateOfLastRemind");
const QString settingUserDefinedMaterials = QStringLiteral("configuration/userDefinedMaterials"); const QString settingUserDefinedMaterials = QStringLiteral("configuration/userDefinedMaterials");
const QString settingCSVWithHeader = QStringLiteral("csv/withHeader");
const QString settingCSVCodec = QStringLiteral("csv/withCodec");
const QString settingCSVSeparator = QStringLiteral("csv/withSeparator");
static const QString commonIniFilename = QStringLiteral("common"); static const QString commonIniFilename = QStringLiteral("common");
#if !defined(Q_OS_WIN) #if !defined(Q_OS_WIN)
@ -612,3 +617,90 @@ void VCommonSettings::SetDoublePassmark(bool value)
{ {
setValue(settingDoublePassmark, value); setValue(settingDoublePassmark, value);
} }
//---------------------------------------------------------------------------------------------------------------------
void VCommonSettings::SetCSVWithHeader(bool withHeader)
{
QSettings settings(this->format(), this->scope(), this->organizationName(), commonIniFilename);
settings.setValue(settingCSVWithHeader, withHeader);
}
//---------------------------------------------------------------------------------------------------------------------
bool VCommonSettings::GetCSVWithHeader() const
{
QSettings settings(this->format(), this->scope(), this->organizationName(), commonIniFilename);
return settings.value(settingCSVWithHeader, GetDefCSVWithHeader()).toBool();
}
//---------------------------------------------------------------------------------------------------------------------
bool VCommonSettings::GetDefCSVWithHeader() const
{
return false;
}
//---------------------------------------------------------------------------------------------------------------------
void VCommonSettings::SetCSVCodec(int mib)
{
QSettings settings(this->format(), this->scope(), this->organizationName(), commonIniFilename);
settings.setValue(settingCSVCodec, mib);
}
//---------------------------------------------------------------------------------------------------------------------
int VCommonSettings::GetCSVCodec() const
{
QSettings settings(this->format(), this->scope(), this->organizationName(), commonIniFilename);
return settings.value(settingCSVCodec, GetDefCSVCodec()).toInt();
}
//---------------------------------------------------------------------------------------------------------------------
int VCommonSettings::GetDefCSVCodec() const
{
return QTextCodec::codecForLocale()->mibEnum();
}
//---------------------------------------------------------------------------------------------------------------------
void VCommonSettings::SetCSVSeparator(const QChar &separator)
{
QSettings settings(this->format(), this->scope(), this->organizationName(), commonIniFilename);
switch(separator.toLatin1())
{
case '\t':
settings.setValue(settingCSVSeparator, 0);
break;
case ';':
settings.setValue(settingCSVSeparator, 1);
break;
case ' ':
settings.setValue(settingCSVSeparator, 2);
break;
case ',':
default:
settings.setValue(settingCSVSeparator, 3);
break;
}
}
//---------------------------------------------------------------------------------------------------------------------
QChar VCommonSettings::GetCSVSeparator() const
{
QSettings settings(this->format(), this->scope(), this->organizationName(), commonIniFilename);
const quint8 separator = static_cast<quint8>(settings.value(settingCSVSeparator, 3).toUInt());
switch(separator)
{
case 0:
return QChar('\t');
case 1:
return QChar(';');
case 2:
return QChar(' ');
case 3:
default:
return QChar(',');
}
}
//---------------------------------------------------------------------------------------------------------------------
QChar VCommonSettings::GetDefCSVSeparator() const
{
return QChar(',');
}

View File

@ -136,6 +136,18 @@ public:
bool IsDoublePassmark() const; bool IsDoublePassmark() const;
void SetDoublePassmark(bool value); void SetDoublePassmark(bool value);
void SetCSVWithHeader(bool withHeader);
bool GetCSVWithHeader() const;
bool GetDefCSVWithHeader() const;
void SetCSVCodec(int mib);
int GetCSVCodec() const;
int GetDefCSVCodec() const;
void SetCSVSeparator(const QChar &separator);
QChar GetCSVSeparator() const;
QChar GetDefCSVSeparator() const;
#if !defined(Q_OS_WIN) #if !defined(Q_OS_WIN)
static const QString unixStandardSharePath; static const QString unixStandardSharePath;
#endif #endif

View File

@ -12,7 +12,8 @@ SOURCES += \
$$PWD/commandoptions.cpp \ $$PWD/commandoptions.cpp \
$$PWD/qxtcsvmodel.cpp \ $$PWD/qxtcsvmodel.cpp \
$$PWD/vtablesearch.cpp \ $$PWD/vtablesearch.cpp \
$$PWD/abstracttest.cpp $$PWD/abstracttest.cpp \
$$PWD/dialogs/dialogexporttocsv.cpp
win32-msvc*:SOURCES += $$PWD/stable.cpp win32-msvc*:SOURCES += $$PWD/stable.cpp
@ -34,7 +35,8 @@ HEADERS += \
$$PWD/qxtcsvmodel.h \ $$PWD/qxtcsvmodel.h \
$$PWD/vtablesearch.h \ $$PWD/vtablesearch.h \
$$PWD/abstracttest.h \ $$PWD/abstracttest.h \
$$PWD/diagnostic.h $$PWD/diagnostic.h \
$$PWD/dialogs/dialogexporttocsv.h
# Qt's versions # Qt's versions
# 5.2.0, 5.2.1 # 5.2.0, 5.2.1
@ -57,3 +59,6 @@ contains(QT_VERSION, ^5\\.[0-2]\\.[0-2]$) { # Since Qt 5.3.0
SOURCES += \ SOURCES += \
$$PWD/backport/qmarginsf.cpp $$PWD/backport/qmarginsf.cpp
} }
FORMS += \
$$PWD/dialogs/dialogexporttocsv.ui

View File

@ -31,7 +31,6 @@
#include <QStaticStringData> #include <QStaticStringData>
#include <QStringData> #include <QStringData>
#include <QStringDataPtr> #include <QStringDataPtr>
#include <QTextCodec>
#include <QVariant> #include <QVariant>
const QString settingDataBaseGeometry = QStringLiteral("database/geometry"); const QString settingDataBaseGeometry = QStringLiteral("database/geometry");
@ -39,10 +38,6 @@ const QString settingDataBaseGeometry = QStringLiteral("database/geometry");
const QString settingDefHeight = QStringLiteral("gradation/defHeight"); const QString settingDefHeight = QStringLiteral("gradation/defHeight");
const QString settingDefSize = QStringLiteral("gradation/defHeight"); const QString settingDefSize = QStringLiteral("gradation/defHeight");
const QString settingCSVWithHeader = QStringLiteral("csv/withHeader");
const QString settingCSVCodec = QStringLiteral("csv/withCodec");
const QString settingCSVSeparator = QStringLiteral("csv/withSeparator");
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VTapeSettings::VTapeSettings(Format format, Scope scope, const QString &organization, const QString &application, VTapeSettings::VTapeSettings(Format format, Scope scope, const QString &organization, const QString &application,
QObject *parent) QObject *parent)
@ -85,84 +80,3 @@ int VTapeSettings::GetDefSize() const
{ {
return value(settingDefSize, 50).toInt(); return value(settingDefSize, 50).toInt();
} }
//---------------------------------------------------------------------------------------------------------------------
void VTapeSettings::SetCSVWithHeader(bool withHeader)
{
setValue(settingCSVWithHeader, withHeader);
}
//---------------------------------------------------------------------------------------------------------------------
bool VTapeSettings::GetCSVWithHeader() const
{
return value(settingCSVWithHeader, GetDefCSVWithHeader()).toBool();
}
//---------------------------------------------------------------------------------------------------------------------
bool VTapeSettings::GetDefCSVWithHeader() const
{
return false;
}
//---------------------------------------------------------------------------------------------------------------------
void VTapeSettings::SetCSVCodec(int mib)
{
setValue(settingCSVCodec, mib);
}
//---------------------------------------------------------------------------------------------------------------------
int VTapeSettings::GetCSVCodec() const
{
return value(settingCSVCodec, GetDefCSVCodec()).toInt();
}
//---------------------------------------------------------------------------------------------------------------------
int VTapeSettings::GetDefCSVCodec() const
{
return QTextCodec::codecForLocale()->mibEnum();
}
//---------------------------------------------------------------------------------------------------------------------
void VTapeSettings::SetCSVSeparator(const QChar &separator)
{
switch(separator.toLatin1())
{
case '\t':
setValue(settingCSVSeparator, 0);
break;
case ';':
setValue(settingCSVSeparator, 1);
break;
case ' ':
setValue(settingCSVSeparator, 2);
break;
case ',':
default:
setValue(settingCSVSeparator, 3);
break;
}
}
//---------------------------------------------------------------------------------------------------------------------
QChar VTapeSettings::GetCSVSeparator() const
{
const quint8 separator = static_cast<quint8>(value(settingCSVSeparator, 3).toUInt());
switch(separator)
{
case 0:
return QChar('\t');
case 1:
return QChar(';');
case 2:
return QChar(' ');
case 3:
default:
return QChar(',');
}
}
//---------------------------------------------------------------------------------------------------------------------
QChar VTapeSettings::GetDefCSVSeparator() const
{
return QChar(',');
}

View File

@ -55,18 +55,6 @@ public:
void SetDefSize(int value); void SetDefSize(int value);
int GetDefSize() const; int GetDefSize() const;
void SetCSVWithHeader(bool withHeader);
bool GetCSVWithHeader() const;
bool GetDefCSVWithHeader() const;
void SetCSVCodec(int mib);
int GetCSVCodec() const;
int GetDefCSVCodec() const;
void SetCSVSeparator(const QChar &separator);
QChar GetCSVSeparator() const;
QChar GetDefCSVSeparator() const;
private: private:
Q_DISABLE_COPY(VTapeSettings) Q_DISABLE_COPY(VTapeSettings)
}; };

View File

@ -4,6 +4,7 @@ unix {
QMAKE_CXXFLAGS += \ QMAKE_CXXFLAGS += \
# Key -isystem disable checking errors in system headers. # Key -isystem disable checking errors in system headers.
-isystem "$${OUT_PWD}/$${MOC_DIR}" \ -isystem "$${OUT_PWD}/$${MOC_DIR}" \
-isystem "$${OUT_PWD}/$${MOC_DIR}" \
$$GCC_DEBUG_CXXFLAGS # See common.pri for more details. $$GCC_DEBUG_CXXFLAGS # See common.pri for more details.
checkWarnings{ # For enable run qmake with CONFIG+=checkWarnings checkWarnings{ # For enable run qmake with CONFIG+=checkWarnings
@ -28,6 +29,7 @@ unix {
QMAKE_CXXFLAGS += \ QMAKE_CXXFLAGS += \
# Key -isystem disable checking errors in system headers. # Key -isystem disable checking errors in system headers.
-isystem "$${OUT_PWD}/$${MOC_DIR}" \ -isystem "$${OUT_PWD}/$${MOC_DIR}" \
-isystem "$${OUT_PWD}/$${MOC_DIR}" \
$$CLANG_DEBUG_CXXFLAGS # See common.pri for more details. $$CLANG_DEBUG_CXXFLAGS # See common.pri for more details.
checkWarnings{ # For enable run qmake with CONFIG+=checkWarnings checkWarnings{ # For enable run qmake with CONFIG+=checkWarnings
@ -43,6 +45,7 @@ unix {
*-icc-*{ *-icc-*{
QMAKE_CXXFLAGS += \ QMAKE_CXXFLAGS += \
-isystem "$${OUT_PWD}/$${MOC_DIR}" \
-isystem "$${OUT_PWD}/$${MOC_DIR}" \ -isystem "$${OUT_PWD}/$${MOC_DIR}" \
$$ICC_DEBUG_CXXFLAGS $$ICC_DEBUG_CXXFLAGS

View File

@ -29,9 +29,11 @@
#include "vabstractmainwindow.h" #include "vabstractmainwindow.h"
#include "../vpropertyexplorer/checkablemessagebox.h" #include "../vpropertyexplorer/checkablemessagebox.h"
#include "../vmisc/vabstractapplication.h" #include "../vmisc/vabstractapplication.h"
#include "dialogs/dialogexporttocsv.h"
#include <QStyle> #include <QStyle>
#include <QToolBar> #include <QToolBar>
#include <QFileDialog>
VAbstractMainWindow::VAbstractMainWindow(QWidget *parent) VAbstractMainWindow::VAbstractMainWindow(QWidget *parent)
: QMainWindow(parent), : QMainWindow(parent),
@ -89,3 +91,34 @@ void VAbstractMainWindow::WindowsLocale()
{ {
qApp->Settings()->GetOsSeparator() ? setLocale(QLocale()) : setLocale(QLocale::c()); qApp->Settings()->GetOsSeparator() ? setLocale(QLocale()) : setLocale(QLocale::c());
} }
//---------------------------------------------------------------------------------------------------------------------
void VAbstractMainWindow::ExportToCSV()
{
const QString filters = tr("Comma-Separated Values") + QLatin1String(" (*.cvs)");
const QString suffix("csv");
const QString path = QDir::homePath() + QLatin1String("/") + tr("values") + QLatin1String(".") + suffix;
QString fileName = QFileDialog::getSaveFileName(this, tr("Export to CSV"), path, filters);
if (fileName.isEmpty())
{
return;
}
QFileInfo f( fileName );
if (f.suffix().isEmpty() && f.suffix() != suffix)
{
fileName += QLatin1String(".") + suffix;
}
DialogExportToCSV dialog(this);
if (dialog.exec() == QDialog::Accepted)
{
ExportToCSVData(fileName, dialog);
qApp->Settings()->SetCSVSeparator(dialog.Separator());
qApp->Settings()->SetCSVCodec(dialog.SelectedMib());
qApp->Settings()->SetCSVWithHeader(dialog.WithHeader());
}
}

View File

@ -35,6 +35,8 @@
#include <QObject> #include <QObject>
#include <QString> #include <QString>
class DialogExportToCSV;
class VAbstractMainWindow : public QMainWindow class VAbstractMainWindow : public QMainWindow
{ {
Q_OBJECT Q_OBJECT
@ -47,6 +49,7 @@ public slots:
protected slots: protected slots:
void WindowsLocale(); void WindowsLocale();
void ExportToCSV();
protected: protected:
int m_curFileFormatVersion; int m_curFileFormatVersion;
@ -54,6 +57,8 @@ 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);
virtual void ExportToCSVData(const QString &fileName, const DialogExportToCSV &dialog)=0;
private: private:
Q_DISABLE_COPY(VAbstractMainWindow) Q_DISABLE_COPY(VAbstractMainWindow)
}; };