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
- [#581] User can now filter input lists by keyword in function wizard.
- [#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/dialognewmeasurements.cpp \
$$PWD/dialogs/dialogmdatabase.cpp \
$$PWD/dialogs/dialogexporttocsv.cpp \
$$PWD/vlitepattern.cpp \
$$PWD/dialogs/dialogtapepreferences.cpp \
$$PWD/dialogs/configpages/tapepreferencesconfigurationpage.cpp \
@ -24,7 +23,6 @@ HEADERS += \
$$PWD/dialogs/dialognewmeasurements.h \
$$PWD/dialogs/dialogmdatabase.h \
$$PWD/version.h \
$$PWD/dialogs/dialogexporttocsv.h \
$$PWD/vlitepattern.h \
$$PWD/dialogs/dialogtapepreferences.h \
$$PWD/dialogs/configpages/tapepreferencesconfigurationpage.h \
@ -35,7 +33,6 @@ FORMS += \
$$PWD/dialogs/dialogabouttape.ui \
$$PWD/dialogs/dialognewmeasurements.ui \
$$PWD/dialogs/dialogmdatabase.ui \
$$PWD/dialogs/dialogexporttocsv.ui \
$$PWD/dialogs/dialogtapepreferences.ui \
$$PWD/dialogs/configpages/tapepreferencesconfigurationpage.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
}
//---------------------------------------------------------------------------------------------------------------------
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()
{
@ -875,80 +924,6 @@ bool TMainWindow::FileSaveAs()
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()
{

View File

@ -70,6 +70,7 @@ protected:
virtual void changeEvent(QEvent* event) Q_DECL_OVERRIDE;
virtual void showEvent(QShowEvent *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:
void FileNew();
@ -82,7 +83,6 @@ private slots:
bool FileSave();
bool FileSaveAs();
void ExportToCSV();
void AboutToShowWindowMenu();
void ShowWindow() const;

View File

@ -39,6 +39,8 @@
#include "../vmisc/undoevent.h"
#include "../vmisc/vsettings.h"
#include "../vmisc/def.h"
#include "../vmisc/qxtcsvmodel.h"
#include "../vmisc/dialogs/dialogexporttocsv.h"
#include "undocommands/renamepp.h"
#include "core/vtooloptionspropertybrowser.h"
#include "options.h"
@ -60,6 +62,7 @@
#include "../vtools/undocommands/addgroup.h"
#include "dialogs/vwidgetdetails.h"
#include "../vpatterndb/vpiecepath.h"
#include "../qmuparser/qmuparsererror.h"
#include <QInputDialog>
#include <QtDebug>
@ -80,6 +83,7 @@
#include <thread>
#include <QFileSystemWatcher>
#include <QComboBox>
#include <QTextCodec>
#if defined(Q_OS_MAC)
#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()
{
@ -3821,6 +3880,7 @@ void MainWindow::CreateActions()
connect(ui->actionSave, &QAction::triggered, this, &MainWindow::Save);
connect(ui->actionOpen, &QAction::triggered, this, &MainWindow::Open);
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)
{

View File

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

View File

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

View File

@ -29,8 +29,8 @@
#include "dialogexporttocsv.h"
#include "ui_dialogexporttocsv.h"
#include "../vmisc/vtapesettings.h"
#include "../mapplication.h"
#include "../vmisc/vcommonsettings.h"
#include "../vabstractapplication.h"
#include <QPushButton>
#include <QShowEvent>
@ -44,25 +44,25 @@ DialogExportToCSV::DialogExportToCSV(QWidget *parent)
{
ui->setupUi(this);
ui->checkBoxWithHeader->setChecked(qApp->TapeSettings()->GetCSVWithHeader());
ui->checkBoxWithHeader->setChecked(qApp->Settings()->GetCSVWithHeader());
foreach (int mib, QTextCodec::availableMibs())
{
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);
SCASSERT(bDefaults != nullptr)
connect(bDefaults, &QPushButton::clicked, RECEIVER(this)[this]()
connect(bDefaults, &QPushButton::clicked, this, [this]()
{
ui->checkBoxWithHeader->setChecked(qApp->TapeSettings()->GetDefCSVWithHeader());
ui->comboBoxCodec->setCurrentIndex(ui->comboBoxCodec->findData(qApp->TapeSettings()->GetDefCSVCodec()));
ui->checkBoxWithHeader->setChecked(qApp->Settings()->GetDefCSVWithHeader());
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 <QVariant>
#include <QtDebug>
#include <QTextCodec>
#include "../vmisc/def.h"
#include "../vmisc/vmath.h"
@ -72,6 +73,10 @@ const QString settingLatestSkippedVersion = QStringLiteral("lastestSkippedVers
const QString settingDateOfLastRemind = QStringLiteral("dateOfLastRemind");
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");
#if !defined(Q_OS_WIN)
@ -612,3 +617,90 @@ void VCommonSettings::SetDoublePassmark(bool 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;
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)
static const QString unixStandardSharePath;
#endif

View File

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

View File

@ -31,7 +31,6 @@
#include <QStaticStringData>
#include <QStringData>
#include <QStringDataPtr>
#include <QTextCodec>
#include <QVariant>
const QString settingDataBaseGeometry = QStringLiteral("database/geometry");
@ -39,10 +38,6 @@ const QString settingDataBaseGeometry = QStringLiteral("database/geometry");
const QString settingDefHeight = 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,
QObject *parent)
@ -85,84 +80,3 @@ int VTapeSettings::GetDefSize() const
{
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);
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:
Q_DISABLE_COPY(VTapeSettings)
};

View File

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

View File

@ -29,9 +29,11 @@
#include "vabstractmainwindow.h"
#include "../vpropertyexplorer/checkablemessagebox.h"
#include "../vmisc/vabstractapplication.h"
#include "dialogs/dialogexporttocsv.h"
#include <QStyle>
#include <QToolBar>
#include <QFileDialog>
VAbstractMainWindow::VAbstractMainWindow(QWidget *parent)
: QMainWindow(parent),
@ -89,3 +91,34 @@ void VAbstractMainWindow::WindowsLocale()
{
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 <QString>
class DialogExportToCSV;
class VAbstractMainWindow : public QMainWindow
{
Q_OBJECT
@ -47,6 +49,7 @@ public slots:
protected slots:
void WindowsLocale();
void ExportToCSV();
protected:
int m_curFileFormatVersion;
@ -54,6 +57,8 @@ protected:
bool ContinueFormatRewrite(const QString &currentFormatVersion, const QString &maxFormatVersion);
void ToolBarStyle(QToolBar *bar);
virtual void ExportToCSVData(const QString &fileName, const DialogExportToCSV &dialog)=0;
private:
Q_DISABLE_COPY(VAbstractMainWindow)
};