From 7225481091fe7d281d8f8fbceaa0d3ea657d73ce Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Fri, 12 May 2017 15:09:19 +0300 Subject: [PATCH] Resolved issue #682. New feature. Export increments to Excel .csv. --HG-- branch : develop --- ChangeLog.txt | 3 + src/app/tape/tape.pri | 3 - src/app/tape/tmainwindow.cpp | 123 +++++++----------- src/app/tape/tmainwindow.h | 2 +- src/app/valentina/mainwindow.cpp | 60 +++++++++ src/app/valentina/mainwindow.h | 1 + src/app/valentina/mainwindow.ui | 26 ++-- .../vmisc}/dialogs/dialogexporttocsv.cpp | 18 +-- .../vmisc}/dialogs/dialogexporttocsv.h | 0 .../vmisc}/dialogs/dialogexporttocsv.ui | 0 src/libs/vmisc/vcommonsettings.cpp | 92 +++++++++++++ src/libs/vmisc/vcommonsettings.h | 12 ++ src/libs/vmisc/vmisc.pri | 9 +- src/libs/vmisc/vtapesettings.cpp | 86 ------------ src/libs/vmisc/vtapesettings.h | 12 -- src/libs/vmisc/warnings.pri | 3 + src/libs/vwidgets/vabstractmainwindow.cpp | 33 +++++ src/libs/vwidgets/vabstractmainwindow.h | 5 + 18 files changed, 291 insertions(+), 197 deletions(-) rename src/{app/tape => libs/vmisc}/dialogs/dialogexporttocsv.cpp (89%) rename src/{app/tape => libs/vmisc}/dialogs/dialogexporttocsv.h (100%) rename src/{app/tape => libs/vmisc}/dialogs/dialogexporttocsv.ui (100%) diff --git a/ChangeLog.txt b/ChangeLog.txt index 74250961a..0c3195ad4 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -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 diff --git a/src/app/tape/tape.pri b/src/app/tape/tape.pri index b0355ca60..77d754cb2 100644 --- a/src/app/tape/tape.pri +++ b/src/app/tape/tape.pri @@ -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 diff --git a/src/app/tape/tmainwindow.cpp b/src/app/tape/tmainwindow.cpp index d3d0c7d78..eedf8d01c 100644 --- a/src/app/tape/tmainwindow.cpp +++ b/src/app/tape/tmainwindow.cpp @@ -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() { diff --git a/src/app/tape/tmainwindow.h b/src/app/tape/tmainwindow.h index b70c7c2c9..fb2aeab6a 100644 --- a/src/app/tape/tmainwindow.h +++ b/src/app/tape/tmainwindow.h @@ -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; diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index 0b61d0de5..823402364 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -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 #include @@ -80,6 +83,7 @@ #include #include #include +#include #if defined(Q_OS_MAC) #include @@ -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 > increments = pattern->DataIncrements(); + QMap >::const_iterator i; + QMap map; + //Sorting QHash by id + for (i = increments.constBegin(); i != increments.constEnd(); ++i) + { + QSharedPointer incr = i.value(); + map.insert(incr->getIndex(), i.key()); + } + + qint32 currentRow = -1; + QMapIterator iMap(map); + while (iMap.hasNext()) + { + iMap.next(); + QSharedPointer 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) { diff --git a/src/app/valentina/mainwindow.h b/src/app/valentina/mainwindow.h index 596b68826..7c428ee58 100644 --- a/src/app/valentina/mainwindow.h +++ b/src/app/valentina/mainwindow.h @@ -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(); diff --git a/src/app/valentina/mainwindow.ui b/src/app/valentina/mainwindow.ui index bf8d4206d..571a248f2 100644 --- a/src/app/valentina/mainwindow.ui +++ b/src/app/valentina/mainwindow.ui @@ -55,7 +55,7 @@ 0 0 - 100 + 127 358 @@ -427,7 +427,7 @@ 0 0 - 100 + 127 110 @@ -536,7 +536,7 @@ 0 0 - 100 + 127 248 @@ -798,7 +798,7 @@ 0 0 - 100 + 127 248 @@ -1146,8 +1146,8 @@ 0 0 - 100 - 196 + 140 + 326 @@ -1324,7 +1324,7 @@ 0 0 - 100 + 127 196 @@ -1511,8 +1511,8 @@ 0 0 - 100 - 58 + 140 + 326 @@ -1679,6 +1679,7 @@ + @@ -2640,6 +2641,11 @@ QAction::NoRole + + + Export increments to CSV + + @@ -2650,8 +2656,8 @@ - + diff --git a/src/app/tape/dialogs/dialogexporttocsv.cpp b/src/libs/vmisc/dialogs/dialogexporttocsv.cpp similarity index 89% rename from src/app/tape/dialogs/dialogexporttocsv.cpp rename to src/libs/vmisc/dialogs/dialogexporttocsv.cpp index 81a4b10c3..5fd938009 100644 --- a/src/app/tape/dialogs/dialogexporttocsv.cpp +++ b/src/libs/vmisc/dialogs/dialogexporttocsv.cpp @@ -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 #include @@ -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()); }); } diff --git a/src/app/tape/dialogs/dialogexporttocsv.h b/src/libs/vmisc/dialogs/dialogexporttocsv.h similarity index 100% rename from src/app/tape/dialogs/dialogexporttocsv.h rename to src/libs/vmisc/dialogs/dialogexporttocsv.h diff --git a/src/app/tape/dialogs/dialogexporttocsv.ui b/src/libs/vmisc/dialogs/dialogexporttocsv.ui similarity index 100% rename from src/app/tape/dialogs/dialogexporttocsv.ui rename to src/libs/vmisc/dialogs/dialogexporttocsv.ui diff --git a/src/libs/vmisc/vcommonsettings.cpp b/src/libs/vmisc/vcommonsettings.cpp index 3c85d9d41..47780c9b8 100644 --- a/src/libs/vmisc/vcommonsettings.cpp +++ b/src/libs/vmisc/vcommonsettings.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #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(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(','); +} diff --git a/src/libs/vmisc/vcommonsettings.h b/src/libs/vmisc/vcommonsettings.h index dda98614b..c2062df19 100644 --- a/src/libs/vmisc/vcommonsettings.h +++ b/src/libs/vmisc/vcommonsettings.h @@ -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 diff --git a/src/libs/vmisc/vmisc.pri b/src/libs/vmisc/vmisc.pri index 3696fbd94..1dafa3f40 100644 --- a/src/libs/vmisc/vmisc.pri +++ b/src/libs/vmisc/vmisc.pri @@ -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 diff --git a/src/libs/vmisc/vtapesettings.cpp b/src/libs/vmisc/vtapesettings.cpp index 1a40c18d4..4ec75ed4c 100644 --- a/src/libs/vmisc/vtapesettings.cpp +++ b/src/libs/vmisc/vtapesettings.cpp @@ -31,7 +31,6 @@ #include #include #include -#include #include 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(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(','); -} diff --git a/src/libs/vmisc/vtapesettings.h b/src/libs/vmisc/vtapesettings.h index 193c090b0..bc7d743e2 100644 --- a/src/libs/vmisc/vtapesettings.h +++ b/src/libs/vmisc/vtapesettings.h @@ -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) }; diff --git a/src/libs/vmisc/warnings.pri b/src/libs/vmisc/warnings.pri index c0fc4e5ea..3471c965d 100644 --- a/src/libs/vmisc/warnings.pri +++ b/src/libs/vmisc/warnings.pri @@ -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 diff --git a/src/libs/vwidgets/vabstractmainwindow.cpp b/src/libs/vwidgets/vabstractmainwindow.cpp index 259dc2f8f..848f14d9a 100644 --- a/src/libs/vwidgets/vabstractmainwindow.cpp +++ b/src/libs/vwidgets/vabstractmainwindow.cpp @@ -29,9 +29,11 @@ #include "vabstractmainwindow.h" #include "../vpropertyexplorer/checkablemessagebox.h" #include "../vmisc/vabstractapplication.h" +#include "dialogs/dialogexporttocsv.h" #include #include +#include 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()); + } +} diff --git a/src/libs/vwidgets/vabstractmainwindow.h b/src/libs/vwidgets/vabstractmainwindow.h index 1fa7c0f14..95e89ab1f 100644 --- a/src/libs/vwidgets/vabstractmainwindow.h +++ b/src/libs/vwidgets/vabstractmainwindow.h @@ -35,6 +35,8 @@ #include #include +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 ¤tFormatVersion, const QString &maxFormatVersion); void ToolBarStyle(QToolBar *bar); + + virtual void ExportToCSVData(const QString &fileName, const DialogExportToCSV &dialog)=0; private: Q_DISABLE_COPY(VAbstractMainWindow) };