Seamly2D
Code documentation
dialogexporttocsv.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * *
3  * Copyright (C) 2017 Seamly, LLC *
4  * *
5  * https://github.com/fashionfreedom/seamly2d *
6  * *
7  ***************************************************************************
8  **
9  ** Seamly2D is free software: you can redistribute it and/or modify
10  ** it under the terms of the GNU General Public License as published by
11  ** the Free Software Foundation, either version 3 of the License, or
12  ** (at your option) any later version.
13  **
14  ** Seamly2D is distributed in the hope that it will be useful,
15  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  ** GNU General Public License for more details.
18  **
19  ** You should have received a copy of the GNU General Public License
20  ** along with Seamly2D. If not, see <http://www.gnu.org/licenses/>.
21  **
22  **************************************************************************
23 
24  ************************************************************************
25  **
26  ** @file dialogexporttocsv.cpp
27  ** @author Roman Telezhynskyi <dismine(at)gmail.com>
28  ** @date 1 6, 2016
29  **
30  ** @brief
31  ** @copyright
32  ** This source code is part of the Valentine project, a pattern making
33  ** program, whose allow create and modeling patterns of clothing.
34  ** Copyright (C) 2016 Seamly2D project
35  ** <https://github.com/fashionfreedom/seamly2d> All Rights Reserved.
36  **
37  ** Seamly2D is free software: you can redistribute it and/or modify
38  ** it under the terms of the GNU General Public License as published by
39  ** the Free Software Foundation, either version 3 of the License, or
40  ** (at your option) any later version.
41  **
42  ** Seamly2D is distributed in the hope that it will be useful,
43  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
44  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
45  ** GNU General Public License for more details.
46  **
47  ** You should have received a copy of the GNU General Public License
48  ** along with Seamly2D. If not, see <http://www.gnu.org/licenses/>.
49  **
50  *************************************************************************/
51 
52 #include "dialogexporttocsv.h"
53 #include "ui_dialogexporttocsv.h"
54 
55 #include "../vmisc/vcommonsettings.h"
56 #include "../vabstractapplication.h"
57 
58 #include <QPushButton>
59 #include <QShowEvent>
60 #include <QTextCodec>
61 
62 //---------------------------------------------------------------------------------------------------------------------
64  : QDialog(parent),
65  ui(new Ui::DialogExportToCSV),
66  isInitialized(false)
67 {
68  ui->setupUi(this);
69 
70  ui->checkBoxWithHeader->setChecked(qApp->Settings()->GetCSVWithHeader());
71 
72  foreach (int mib, QTextCodec::availableMibs())
73  {
74  ui->comboBoxCodec->addItem(QTextCodec::codecForMib(mib)->name(), mib);
75  }
76 
77  ui->comboBoxCodec->setCurrentIndex(ui->comboBoxCodec->findData(qApp->Settings()->GetCSVCodec()));
78 
79  SetSeparator(qApp->Settings()->GetCSVSeparator());
80 
81  QPushButton *bDefaults = ui->buttonBox->button(QDialogButtonBox::RestoreDefaults);
82  SCASSERT(bDefaults != nullptr)
83  connect(bDefaults, &QPushButton::clicked, this, [this]()
84  {
85  ui->checkBoxWithHeader->setChecked(qApp->Settings()->GetDefCSVWithHeader());
86  ui->comboBoxCodec->setCurrentIndex(ui->comboBoxCodec->findData(qApp->Settings()->GetDefCSVCodec()));
87 
88  SetSeparator(qApp->Settings()->GetDefCSVSeparator());
89  });
90 }
91 
92 //---------------------------------------------------------------------------------------------------------------------
94 {
95  delete ui;
96 }
97 
98 //---------------------------------------------------------------------------------------------------------------------
100 {
101  return ui->checkBoxWithHeader->isChecked();
102 }
103 
104 //---------------------------------------------------------------------------------------------------------------------
106 {
107  return ui->comboBoxCodec->currentData().toInt();
108 }
109 
110 //---------------------------------------------------------------------------------------------------------------------
112 {
113  if (ui->radioButtonTab->isChecked())
114  {
115  return QChar('\t');
116  }
117  else if (ui->radioButtonSemicolon->isChecked())
118  {
119  return QChar(';');
120  }
121  else if (ui->radioButtonSpace->isChecked())
122  {
123  return QChar(' ');
124  }
125  else
126  {
127  return QChar(',');
128  }
129 }
130 
131 //---------------------------------------------------------------------------------------------------------------------
133 {
134  if (event->type() == QEvent::LanguageChange)
135  {
136  // retranslate designer form (single inheritance approach)
137  ui->retranslateUi(this);
138  }
139 
140  // remember to call base class implementation
141  QDialog::changeEvent(event);
142 }
143 
144 //---------------------------------------------------------------------------------------------------------------------
145 void DialogExportToCSV::showEvent(QShowEvent *event)
146 {
147  QDialog::showEvent( event );
148  if ( event->spontaneous() )
149  {
150  return;
151  }
152 
153  if (isInitialized)
154  {
155  return;
156  }
157  // do your init stuff here
158 
159  setMaximumSize(size());
160  setMinimumSize(size());
161 
162  isInitialized = true;//first show windows are held
163 }
164 
165 //---------------------------------------------------------------------------------------------------------------------
166 void DialogExportToCSV::SetSeparator(const QChar &separator)
167 {
168  switch(separator.toLatin1())
169  {
170  case '\t':
171  ui->radioButtonTab->setChecked(true);
172  break;
173  case ';':
174  ui->radioButtonSemicolon->setChecked(true);
175  break;
176  case ' ':
177  ui->radioButtonSpace->setChecked(true);
178  break;
179  case ',':
180  default:
181  ui->radioButtonComma->setChecked(true);
182  break;
183  }
184 }
void SetSeparator(const QChar &separator)
Ui::DialogExportToCSV * ui
virtual void changeEvent(QEvent *event) Q_DECL_OVERRIDE
DialogExportToCSV(QWidget *parent=nullptr)
virtual void showEvent(QShowEvent *event) Q_DECL_OVERRIDE
#define SCASSERT(cond)
Definition: def.h:317
#define qApp
Definition: vapplication.h:67