Seamly2D
Code documentation
seamlymepreferencespathpage.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 seamlymepreferencespathpage.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 
53 #include "ui_seamlymepreferencespathpage.h"
54 #include "../../mapplication.h"
55 #include "../vmisc/vseamlymesettings.h"
56 
57 #include <QDir>
58 #include <QFileDialog>
59 
60 //---------------------------------------------------------------------------------------------------------------------
62  : QWidget(parent),
64 {
65  ui->setupUi(this);
66 
67  InitTable();
68 
69  connect(ui->defaultButton, &QPushButton::clicked, this, &SeamlyMePreferencesPathPage::DefaultPath);
70  connect(ui->editButton, &QPushButton::clicked, this, &SeamlyMePreferencesPathPage::EditPath);
71 }
72 
73 //---------------------------------------------------------------------------------------------------------------------
75 {
76  delete ui;
77 }
78 
79 //---------------------------------------------------------------------------------------------------------------------
81 {
82  VSeamlyMeSettings *settings = qApp->SeamlyMeSettings();
83  settings->SetPathIndividualMeasurements(ui->pathTable->item(0, 1)->text());
84  settings->SetPathMultisizeMeasurements(ui->pathTable->item(1, 1)->text());
85  settings->SetPathTemplate(ui->pathTable->item(2, 1)->text());
86 }
87 
88 //---------------------------------------------------------------------------------------------------------------------
90 {
91  const int row = ui->pathTable->currentRow();
92  QTableWidgetItem *item = ui->pathTable->item(row, 1);
93  SCASSERT(item != nullptr)
94 
95  QString path;
96  switch (row)
97  {
98  case 0: // individual measurements
100  break;
101  case 1: // multisize measurements
103  break;
104  case 2: // templates
106  break;
107  default:
108  break;
109  }
110 
111  item->setText(path);
112  item->setToolTip(path);
113 }
114 
115 //---------------------------------------------------------------------------------------------------------------------
117 {
118  const int row = ui->pathTable->currentRow();
119  QTableWidgetItem *item = ui->pathTable->item(row, 1);
120  SCASSERT(item != nullptr)
121 
122  QString path;
123  switch (row)
124  {
125  case 0: // individual measurements
126  path = qApp->SeamlyMeSettings()->GetPathIndividualMeasurements();
127  break;
128  case 1: // multisize measurements
129  path = qApp->SeamlyMeSettings()->GetPathMultisizeMeasurements();
131  break;
132  case 2: // templates
133  path = qApp->SeamlyMeSettings()->GetPathTemplate();
134  break;
135  default:
136  break;
137  }
138 
139  bool usedNotExistedDir = false;
140  QDir directory(path);
141  if (not directory.exists())
142  {
143  usedNotExistedDir = directory.mkpath(".");
144  }
145 
146  const QString dir = QFileDialog::getExistingDirectory(this, tr("Open Directory"), path,
147  QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
148  if (dir.isEmpty())
149  {
150  if (usedNotExistedDir)
151  {
152  QDir directory(path);
153  directory.rmpath(".");
154  }
155 
156  DefaultPath();
157  return;
158  }
159 
160  item->setText(dir);
161  item->setToolTip(dir);
162 }
163 
164 //---------------------------------------------------------------------------------------------------------------------
166 {
167  ui->pathTable->setRowCount(3);
168  ui->pathTable->setColumnCount(2);
169 
170  const VSeamlyMeSettings *settings = qApp->SeamlyMeSettings();
171 
172  {
173  ui->pathTable->setItem(0, 0, new QTableWidgetItem(tr("My Individual Measurements")));
174  QTableWidgetItem *item = new QTableWidgetItem(settings->GetPathIndividualMeasurements());
175  item->setToolTip(settings->GetPathIndividualMeasurements());
176  ui->pathTable->setItem(0, 1, item);
177  }
178 
179  {
180  ui->pathTable->setItem(1, 0, new QTableWidgetItem(tr("My Multisize Measurements")));
181  QTableWidgetItem *item = new QTableWidgetItem(settings->GetPathMultisizeMeasurements());
182  item->setToolTip(settings->GetPathMultisizeMeasurements());
183  ui->pathTable->setItem(1, 1, item);
184  }
185 
186  {
187  ui->pathTable->setItem(2, 0, new QTableWidgetItem(tr("My Templates")));
188  QTableWidgetItem *item = new QTableWidgetItem(settings->GetPathTemplate());
189  item->setToolTip(settings->GetPathTemplate());
190  ui->pathTable->setItem(2, 1, item);
191  }
192 
193  ui->pathTable->verticalHeader()->setDefaultSectionSize(20);
194  ui->pathTable->resizeColumnsToContents();
195  ui->pathTable->resizeRowsToContents();
196  ui->pathTable->horizontalHeader()->setStretchLastSection(true);
197 
198  connect(ui->pathTable, &QTableWidget::itemSelectionChanged, this, [this]()
199  {
200  ui->defaultButton->setEnabled(true);
201  ui->defaultButton->setDefault(false);
202 
203  ui->editButton->setEnabled(true);
204  ui->editButton->setDefault(true);
205  });
206 }
Ui::SeamlyMePreferencesPathPage * ui
SeamlyMePreferencesPathPage(QWidget *parent=nullptr)
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)
static QString GetDefPathIndividualMeasurements()
void SetPathTemplate(const QString &value)
void SetPathMultisizeMeasurements(const QString &value)
#define SCASSERT(cond)
Definition: def.h:317
#define qApp
Definition: vapplication.h:67