Seamly2D
Code documentation
vabstractmainwindow.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  * @file vabstractmainwindow.cpp
3  ** @author Douglas S Caskey
4  ** @date 13 May, 2023
5  **
6  ** @brief
7  ** @copyright
8  ** This source code is part of the Seamly2D project, a pattern making
9  ** program to create and model patterns of clothing.
10  ** Copyright (C) 2017-2023 Seamly2D project
11  ** <https://github.com/fashionfreedom/seamly2d> All Rights Reserved.
12  **
13  ** Seamly2D is free software: you can redistribute it and/or modify
14  ** it under the terms of the GNU General Public License as published by
15  ** the Free Software Foundation, either version 3 of the License, or
16  ** (at your option) any later version.
17  **
18  ** Seamly2D is distributed in the hope that it will be useful,
19  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
20  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  ** GNU General Public License for more details.
22  **
23  ** You should have received a copy of the GNU General Public License
24  ** along with Seamly2D. If not, see <http://www.gnu.org/licenses/>.
25  **
26  *************************************************************************/
27 
28 /************************************************************************
29  **
30  ** @file
31  ** @author Valentina Zhuravska <zhuravska19(at)gmail.com>
32  ** @date 19 7, 2016
33  **
34  ** @brief
35  ** @copyright
36  ** This source code is part of the Valentina project, a pattern making
37  ** program, whose allow create and modeling patterns of clothing.
38  ** Copyright (C) 2016 Valentina project
39  ** <https://github.com/fashionfreedom/seamly2d> All Rights Reserved.
40  **
41  ** Valentina is free software: you can redistribute it and/or modify
42  ** it under the terms of the GNU General Public License as published by
43  ** the Free Software Foundation, either version 3 of the License, or
44  ** (at your option) any later version.
45  **
46  ** Valentina is distributed in the hope that it will be useful,
47  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
48  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
49  ** GNU General Public License for more details.
50  **
51  ** You should have received a copy of the GNU General Public License
52  ** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
53  **
54  *************************************************************************/
55 
56 #include "vabstractmainwindow.h"
57 #include "../vpropertyexplorer/checkablemessagebox.h"
58 #include "../vmisc/vabstractapplication.h"
60 
61 #include <QStyle>
62 #include <QToolBar>
63 #include <QFileDialog>
64 
66  : QMainWindow(parent),
67  m_curFileFormatVersion(0x0),
68  m_curFileFormatVersionStr(QLatin1String("0.0.0"))
69 {}
70 
71 //---------------------------------------------------------------------------------------------------------------------
72 bool VAbstractMainWindow::ContinueFormatRewrite(const QString &currentFormatVersion,
73  const QString &maxFormatVersion)
74 {
75  if (qApp->Settings()->getConfirmFormatRewriting())
76  {
77  Utils::CheckableMessageBox msgBox(this);
78  msgBox.setWindowTitle(tr("Confirm format rewriting"));
79  msgBox.setText(tr("This file is using previous format version v%1. The current is v%2. "
80  "Saving the file with this app version will update the format version for this "
81  "file. This may prevent you from be able to open the file with older app versions. "
82  "Do you really want to continue?").arg(currentFormatVersion).arg(maxFormatVersion));
83  msgBox.setStandardButtons(QDialogButtonBox::Yes | QDialogButtonBox::No);
84  msgBox.setDefaultButton(QDialogButtonBox::No);
85  msgBox.setIconPixmap(QApplication::style()->standardIcon(QStyle::SP_MessageBoxQuestion).pixmap(32, 32));
86 
87  int dialogResult = msgBox.exec();
88 
89  if (dialogResult == QDialog::Accepted)
90  {
91  qApp->Settings()->setConfirmFormatRewriting(not msgBox.isChecked());
92  return true;
93  }
94  else
95  {
96  return false;
97  }
98  }
99  return true;
100 }
101 
102 //---------------------------------------------------------------------------------------------------------------------
104 {
105  SCASSERT(bar != nullptr)
106  if (qApp->Settings()->getToolBarStyle())
107  {
108  bar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
109  }
110  else
111  {
112  bar->setToolButtonStyle(Qt::ToolButtonIconOnly);
113  }
114 }
115 
116 //---------------------------------------------------------------------------------------------------------------------
118 {
119  qApp->Settings()->GetOsSeparator() ? setLocale(QLocale()) : setLocale(QLocale::c());
120 }
121 
122 //---------------------------------------------------------------------------------------------------------------------
124 {
125  const QString filters = tr("Comma-Separated Values") + QLatin1String(" (*.csv)");
126  const QString suffix("csv");
127  const QString path = QDir::homePath() + QLatin1String("/") + file + QLatin1String(".") + suffix;
128 
129  QString fileName = QFileDialog::getSaveFileName(this, tr("Export to CSV"), path, filters, nullptr,
130  QFileDialog::DontUseNativeDialog);
131 
132  if (fileName.isEmpty())
133  {
134  return;
135  }
136 
137  QFileInfo f( fileName );
138  if (f.suffix().isEmpty() && f.suffix() != suffix)
139  {
140  fileName += QLatin1String(".") + suffix;
141  }
142 
143  DialogExportToCSV dialog(this);
144  if (dialog.exec() == QDialog::Accepted)
145  {
146  exportToCSVData(fileName, dialog);
147 
148  qApp->Settings()->SetCSVSeparator(dialog.Separator());
149  qApp->Settings()->SetCSVCodec(dialog.SelectedMib());
150  qApp->Settings()->SetCSVWithHeader(dialog.WithHeader());
151  }
152 }
153 
154 //---------------------------------------------------------------------------------------------------------------------
156 {
157  // do nothing
158 }
The CheckableMessageBox class implements a message box suitable for questions with a "Do not ask me a...
void setStandardButtons(QDialogButtonBox::StandardButtons s)
void setIconPixmap(const QPixmap &p)
void setDefaultButton(QDialogButtonBox::StandardButton s)
virtual void exportToCSVData(const QString &fileName, const DialogExportToCSV &dialog)=0
virtual void zoomToSelected()=0
void exportToCSV(QString &file)
void ToolBarStyle(QToolBar *bar)
VAbstractMainWindow(QWidget *parent=nullptr)
bool ContinueFormatRewrite(const QString &currentFormatVersion, const QString &maxFormatVersion)
#define SCASSERT(cond)
Definition: def.h:317
#define qApp
Definition: vapplication.h:67