2016-07-25 18:23:00 +02:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file
|
|
|
|
** @author Valentina Zhuravska <zhuravska19(at)gmail.com>
|
|
|
|
** @date 19 7, 2016
|
|
|
|
**
|
|
|
|
** @brief
|
|
|
|
** @copyright
|
2017-10-05 11:20:01 +02:00
|
|
|
** This source code is part of the Valentina project, a pattern making
|
2016-07-25 18:23:00 +02:00
|
|
|
** program, whose allow create and modeling patterns of clothing.
|
|
|
|
** Copyright (C) 2016 Valentina project
|
|
|
|
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
|
|
|
|
**
|
|
|
|
** Valentina is free software: you can redistribute it and/or modify
|
|
|
|
** it under the terms of the GNU General Public License as published by
|
|
|
|
** the Free Software Foundation, either version 3 of the License, or
|
|
|
|
** (at your option) any later version.
|
|
|
|
**
|
|
|
|
** Valentina is distributed in the hope that it will be useful,
|
|
|
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
** GNU General Public License for more details.
|
|
|
|
**
|
|
|
|
** You should have received a copy of the GNU General Public License
|
|
|
|
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
**
|
|
|
|
*************************************************************************/
|
|
|
|
|
|
|
|
#include "vabstractmainwindow.h"
|
2017-04-12 08:49:05 +02:00
|
|
|
#include "../vpropertyexplorer/checkablemessagebox.h"
|
|
|
|
#include "../vmisc/vabstractapplication.h"
|
2017-05-12 14:09:19 +02:00
|
|
|
#include "dialogs/dialogexporttocsv.h"
|
2016-07-25 18:23:00 +02:00
|
|
|
|
2017-04-12 08:49:05 +02:00
|
|
|
#include <QStyle>
|
2017-04-12 14:50:48 +02:00
|
|
|
#include <QToolBar>
|
2017-05-12 14:09:19 +02:00
|
|
|
#include <QFileDialog>
|
2017-04-12 08:49:05 +02:00
|
|
|
|
2018-03-12 11:25:02 +01:00
|
|
|
#if defined(Q_OS_MAC)
|
|
|
|
#include "../vwidgets/vmaingraphicsview.h"
|
|
|
|
#include <QStyleFactory>
|
|
|
|
#endif
|
|
|
|
|
2017-04-12 08:49:05 +02:00
|
|
|
VAbstractMainWindow::VAbstractMainWindow(QWidget *parent)
|
|
|
|
: QMainWindow(parent),
|
|
|
|
m_curFileFormatVersion(0x0),
|
|
|
|
m_curFileFormatVersionStr(QLatin1String("0.0.0"))
|
2016-07-25 18:23:00 +02:00
|
|
|
{}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-04-12 08:49:05 +02:00
|
|
|
bool VAbstractMainWindow::ContinueFormatRewrite(const QString ¤tFormatVersion,
|
|
|
|
const QString &maxFormatVersion)
|
|
|
|
{
|
|
|
|
if (qApp->Settings()->GetConfirmFormatRewriting())
|
|
|
|
{
|
|
|
|
Utils::CheckableMessageBox msgBox(this);
|
|
|
|
msgBox.setWindowTitle(tr("Confirm format rewriting"));
|
|
|
|
msgBox.setText(tr("This file is using previous format version v%1. The current is v%2. "
|
|
|
|
"Saving the file with this app version will update the format version for this "
|
2017-04-24 16:20:15 +02:00
|
|
|
"file. This may prevent you from be able to open the file with older app versions. "
|
2017-04-12 08:49:05 +02:00
|
|
|
"Do you really want to continue?").arg(currentFormatVersion).arg(maxFormatVersion));
|
|
|
|
msgBox.setStandardButtons(QDialogButtonBox::Yes | QDialogButtonBox::No);
|
|
|
|
msgBox.setDefaultButton(QDialogButtonBox::No);
|
|
|
|
msgBox.setIconPixmap(QApplication::style()->standardIcon(QStyle::SP_MessageBoxQuestion).pixmap(32, 32));
|
|
|
|
|
|
|
|
int dialogResult = msgBox.exec();
|
|
|
|
|
|
|
|
if (dialogResult == QDialog::Accepted)
|
|
|
|
{
|
|
|
|
qApp->Settings()->SetConfirmFormatRewriting(not msgBox.isChecked());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2017-04-12 14:50:48 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VAbstractMainWindow::ToolBarStyle(QToolBar *bar)
|
|
|
|
{
|
|
|
|
SCASSERT(bar != nullptr)
|
|
|
|
if (qApp->Settings()->GetToolBarStyle())
|
|
|
|
{
|
|
|
|
bar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bar->setToolButtonStyle(Qt::ToolButtonIconOnly);
|
|
|
|
}
|
2018-03-12 11:25:02 +01:00
|
|
|
|
|
|
|
#if defined(Q_OS_MAC)
|
|
|
|
// Temporary fix issue with toolbar black background on mac with OpenGL render
|
|
|
|
if (qApp->getSceneView() && qApp->getSceneView()->IsOpenGLRender())
|
|
|
|
{
|
|
|
|
bar->setStyle(QStyleFactory::create("fusion"));
|
|
|
|
}
|
|
|
|
#endif
|
2017-04-12 14:50:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-09-27 12:25:18 +02:00
|
|
|
QString VAbstractMainWindow::CSVFilePath()
|
2017-05-12 14:09:19 +02:00
|
|
|
{
|
2017-05-17 06:57:46 +02:00
|
|
|
const QString filters = tr("Comma-Separated Values") + QLatin1String(" (*.csv)");
|
2017-05-12 14:09:19 +02:00
|
|
|
const QString suffix("csv");
|
|
|
|
const QString path = QDir::homePath() + QLatin1String("/") + tr("values") + QLatin1String(".") + suffix;
|
|
|
|
|
2017-06-19 15:11:44 +02:00
|
|
|
QString fileName = QFileDialog::getSaveFileName(this, tr("Export to CSV"), path, filters, nullptr,
|
|
|
|
QFileDialog::DontUseNativeDialog);
|
2017-05-12 14:09:19 +02:00
|
|
|
|
|
|
|
if (fileName.isEmpty())
|
|
|
|
{
|
2017-09-27 12:25:18 +02:00
|
|
|
return fileName;
|
2017-05-12 14:09:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QFileInfo f( fileName );
|
|
|
|
if (f.suffix().isEmpty() && f.suffix() != suffix)
|
|
|
|
{
|
|
|
|
fileName += QLatin1String(".") + suffix;
|
|
|
|
}
|
|
|
|
|
2017-09-27 12:25:18 +02:00
|
|
|
return fileName;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VAbstractMainWindow::WindowsLocale()
|
|
|
|
{
|
|
|
|
qApp->Settings()->GetOsSeparator() ? setLocale(QLocale()) : setLocale(QLocale::c());
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VAbstractMainWindow::ExportDataToCSV()
|
|
|
|
{
|
|
|
|
QString fileName = CSVFilePath();
|
|
|
|
|
|
|
|
if (fileName.isEmpty())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-05-12 14:09:19 +02:00
|
|
|
DialogExportToCSV dialog(this);
|
2017-09-27 12:25:18 +02:00
|
|
|
dialog.SetWithHeader(qApp->Settings()->GetCSVWithHeader());
|
|
|
|
dialog.SetSelectedMib(qApp->Settings()->GetCSVCodec());
|
|
|
|
dialog.SetSeparator(qApp->Settings()->GetCSVSeparator());
|
|
|
|
|
2017-05-12 14:09:19 +02:00
|
|
|
if (dialog.exec() == QDialog::Accepted)
|
|
|
|
{
|
2017-09-27 12:25:18 +02:00
|
|
|
ExportToCSVData(fileName, dialog.IsWithHeader(), dialog.GetSelectedMib(), dialog.GetSeparator());
|
2017-05-12 14:09:19 +02:00
|
|
|
|
2017-09-27 12:25:18 +02:00
|
|
|
qApp->Settings()->SetCSVSeparator(dialog.GetSeparator());
|
|
|
|
qApp->Settings()->SetCSVCodec(dialog.GetSelectedMib());
|
|
|
|
qApp->Settings()->SetCSVWithHeader(dialog.IsWithHeader());
|
2017-05-12 14:09:19 +02:00
|
|
|
}
|
|
|
|
}
|