Seamly2D
Code documentation
preferencespathpage.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 preferencespathpage.cpp
27  ** @author Roman Telezhynskyi <dismine(at)gmail.com>
28  ** @date 12 4, 2017
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) 2017 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 "preferencespathpage.h"
53 #include "ui_preferencespathpage.h"
54 #include "../vmisc/vsettings.h"
55 #include "../../options.h"
56 #include "../../core/vapplication.h"
57 
58 #include <QDir>
59 #include <QFileDialog>
60 
61 //---------------------------------------------------------------------------------------------------------------------
63  : QWidget(parent),
64  ui(new Ui::PreferencesPathPage)
65 {
66  ui->setupUi(this);
67 
68  InitTable();
69 
70  connect(ui->defaultButton, &QPushButton::clicked, this, &PreferencesPathPage::DefaultPath);
71  connect(ui->editButton, &QPushButton::clicked, this, &PreferencesPathPage::EditPath);
72 }
73 
74 //---------------------------------------------------------------------------------------------------------------------
76 {
77  delete ui;
78 }
79 
80 //---------------------------------------------------------------------------------------------------------------------
82 {
83  VSettings *settings = qApp->Seamly2DSettings();
84  settings->SetPathIndividualMeasurements(ui->pathTable->item(0, 1)->text());
85  settings->SetPathMultisizeMeasurements(ui->pathTable->item(1, 1)->text());
86  settings->SetPathPattern(ui->pathTable->item(2, 1)->text());
87  settings->SetPathLayout(ui->pathTable->item(3, 1)->text());
88  settings->SetPathTemplate(ui->pathTable->item(4, 1)->text());
89  settings->SetPathLabelTemplate(ui->pathTable->item(5, 1)->text());
90 }
91 
92 //---------------------------------------------------------------------------------------------------------------------
94 {
95  const int row = ui->pathTable->currentRow();
96  QTableWidgetItem *item = ui->pathTable->item(row, 1);
97  SCASSERT(item != nullptr)
98 
99  QString path;
100 
101  switch (row)
102  {
103  case 1: // multisize measurements
105  break;
106  case 2: // pattern path
108  break;
109  case 0: // individual measurements
111  break;
112  case 3: // layout path
114  break;
115  case 4: // templates
117  break;
118  case 5: // label templates
120  break;
121  default:
122  break;
123  }
124 
125  item->setText(path);
126  item->setToolTip(path);
127 }
128 
129 //---------------------------------------------------------------------------------------------------------------------
131 {
132  const int row = ui->pathTable->currentRow();
133  QTableWidgetItem *item = ui->pathTable->item(row, 1);
134  SCASSERT(item != nullptr)
135 
136  QString path;
137  switch (row)
138  {
139  case 0: // individual measurements
140  path = qApp->Seamly2DSettings()->GetPathIndividualMeasurements();
141  break;
142  case 1: // multisize measurements
143  path = qApp->Seamly2DSettings()->GetPathMultisizeMeasurements();
145  break;
146  case 2: // pattern path
147  path = qApp->Seamly2DSettings()->GetPathPattern();
148  break;
149  case 3: // layout path
150  path = qApp->Seamly2DSettings()->getLayoutPath();
151  break;
152  case 4: // templates
153  path = qApp->Seamly2DSettings()->GetPathTemplate();
154  break;
155  case 5: // label templates
156  path = qApp->Seamly2DSettings()->GetPathLabelTemplate();
157  break;
158  default:
159  break;
160  }
161 
162  bool usedNotExistedDir = false;
163  QDir directory(path);
164  if (not directory.exists())
165  {
166  usedNotExistedDir = directory.mkpath(".");
167  }
168 
169  const QString dir = QFileDialog::getExistingDirectory(this, tr("Open Directory"), path,
170  QFileDialog::ShowDirsOnly
171  | QFileDialog::DontResolveSymlinks
172  | QFileDialog::DontUseNativeDialog);
173  if (dir.isEmpty())
174  {
175  if (usedNotExistedDir)
176  {
177  QDir directory(path);
178  directory.rmpath(".");
179  }
180  DefaultPath();
181  return;
182  }
183 
184  item->setText(dir);
185  item->setToolTip(dir);
186 
187  if (usedNotExistedDir)
188  {
189  QDir directory(path);
190  directory.rmpath(".");
191  }
192 }
193 
194 //---------------------------------------------------------------------------------------------------------------------
196 {
197  ui->pathTable->setRowCount(6);
198  ui->pathTable->setColumnCount(2);
199 
200  const VSettings *settings = qApp->Seamly2DSettings();
201 
202  {
203  ui->pathTable->setItem(0, 0, new QTableWidgetItem(tr("My Individual Measurements")));
204  QTableWidgetItem *item = new QTableWidgetItem(settings->GetPathIndividualMeasurements());
205  item->setToolTip(settings->GetPathIndividualMeasurements());
206  ui->pathTable->setItem(0, 1, item);
207  }
208 
209  {
210  ui->pathTable->setItem(1, 0, new QTableWidgetItem(tr("My Multisize Measurements")));
211  QTableWidgetItem *item = new QTableWidgetItem(settings->GetPathMultisizeMeasurements());
212  item->setToolTip(settings->GetPathMultisizeMeasurements());
213  ui->pathTable->setItem(1, 1, item);
214  }
215 
216  {
217  ui->pathTable->setItem(2, 0, new QTableWidgetItem(tr("My Patterns")));
218  QTableWidgetItem *item = new QTableWidgetItem(settings->GetPathPattern());
219  item->setToolTip(settings->GetPathPattern());
220  ui->pathTable->setItem(2, 1, item);
221  }
222 
223  {
224  ui->pathTable->setItem(3, 0, new QTableWidgetItem(tr("My Layouts")));
225  QTableWidgetItem *item = new QTableWidgetItem(settings->getLayoutPath());
226  item->setToolTip(settings->getLayoutPath());
227  ui->pathTable->setItem(3, 1, item);
228  }
229 
230  {
231  ui->pathTable->setItem(4, 0, new QTableWidgetItem(tr("My Templates")));
232  QTableWidgetItem *item = new QTableWidgetItem(settings->GetPathTemplate());
233  item->setToolTip(settings->GetPathTemplate());
234  ui->pathTable->setItem(4, 1, item);
235  }
236 
237  {
238  ui->pathTable->setItem(5, 0, new QTableWidgetItem(tr("My label templates")));
239  QTableWidgetItem *item = new QTableWidgetItem(settings->GetPathLabelTemplate());
240  item->setToolTip(settings->GetPathLabelTemplate());
241  ui->pathTable->setItem(5, 1, item);
242  }
243 
244  ui->pathTable->verticalHeader()->setDefaultSectionSize(20);
245  ui->pathTable->resizeColumnsToContents();
246  ui->pathTable->resizeRowsToContents();
247 
248  connect(ui->pathTable, &QTableWidget::itemSelectionChanged, this, [this]()
249  {
250  ui->defaultButton->setEnabled(true);
251  ui->defaultButton->setDefault(false);
252 
253  ui->editButton->setEnabled(true);
254  ui->editButton->setDefault(true);
255  });
256 }
Ui::PreferencesPathPage * ui
PreferencesPathPage(QWidget *parent=nullptr)
void SetPathLabelTemplate(const QString &value)
static QString GetDefPathMultisizeMeasurements()
static QString GetDefPathTemplate()
static QString PrepareMultisizeTables(const QString &currentPath)
QString GetPathIndividualMeasurements() const
QString GetPathTemplate() const
QString GetPathMultisizeMeasurements() const
void SetPathIndividualMeasurements(const QString &value)
QString GetPathLabelTemplate() const
static QString GetDefPathIndividualMeasurements()
void SetPathTemplate(const QString &value)
void SetPathMultisizeMeasurements(const QString &value)
static QString GetDefPathLabelTemplate()
static QString GetDefPathLayout()
Definition: vsettings.cpp:155
static QString GetDefPathPattern()
Definition: vsettings.cpp:134
void SetPathPattern(const QString &value)
Definition: vsettings.cpp:147
void SetPathLayout(const QString &value)
Definition: vsettings.cpp:168
QString GetPathPattern() const
Definition: vsettings.cpp:140
QString getLayoutPath() const
Definition: vsettings.cpp:161
#define SCASSERT(cond)
Definition: def.h:317
#define qApp
Definition: vapplication.h:67